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 EECS1030Z_2014_15W * */ public abstract class AbstractBankAccount { private 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.
*
*/
public abstract void update();
}