package cse1030; /** * A simple abstract class for representing bank accounts. The balance is * stored as an integer amount (presumably in cents for a North American * bank account). * * @author CSE1030Z * */ public abstract class AbstractBankAccount { protected long balance; /** * Create a bank account with the given starting balance. * * @param balance the starting balance of the account */ protected AbstractBankAccount(long balance) { this.balance = balance; } /** * Deposit an amount of currency into the account. * *

* Exactly how the balance of the account is affected by the * deposit is determined by the subclasses; the default * behavior supplied by AbstractBankAccount is to add the * deposit amount to the balance. * * @param amount the amount of currency to deposit into the account * @throws IllegalArgumentException if amount < 0 */ public void deposit(long amount) { if (amount < 0) { throw new IllegalArgumentException("deposit amount:" + amount + " is negative"); } this.balance += amount; } /** * Withdraw an amount of currency from the account. * *

* Exactly how the balance of the account is affected by the * withdrawal is determined by the subclasses; the default * behavior supplied by AbstractBankAccount is to subtract the * withdrawal amount from the balance. * * @param amount the amount of currency to withdraw from the account * @throws IllegalArgumentException if amount < 0 */ public void withdraw(long amount) { if (amount < 0) { throw new IllegalArgumentException("withdraw amount:" + amount + " is negative"); } this.balance -= amount; } /** * Return the account balance. * * @return the account balance */ public long getBalance() { return this.balance; } /** * Update the account balance to reflect specific policies on the account; * for example, a savings account might add interest to the account * balance. * * @param d the date when the update is performed */ public abstract void update(); }