Class BankAccount

java.lang.Object
  extended byBankAccount
Direct Known Subclasses:
CheckingAccount, FeeAccount, RegularAccount, SavingsAccount

public abstract class BankAccount
extends Object

A BankAccount object has private fields to keep track of its current balance, the number of transactions performed and the Bank in which it is an account, and and public methods to access those fields appropriately.

Version:
7
See Also:
Bank

Constructor Summary
protected BankAccount(int initialBalance, Bank issuingBank)
          Construct a BankAccount with the given initial balance and issuing Bank.
 
Method Summary
 void countTransaction()
          Increment by 1 the count of transactions, for this account and for the issuing Bank.
 int deposit(int amount)
          Deposit the given amount, increasing this BankAccount's balance and the issuing Bank's balance.
 int getBalance()
          Get the current balance.
protected  Bank getIssuingBank()
          The bank that issued this account.
 int getTransactionCount()
          Get the number of transactions performed by this account.
protected  int getTransactionFee()
          Get transaction fee.
 void incrementBalance(int amount)
          Increment account balance by given amount.
abstract  void newMonth()
          Action to take when a new month starts.
 int requestBalance()
          Request for balance.
 int withdraw(int amount)
          Withdraw the given amount, decreasing this BankAccount's balance and the issuing Bank's balance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BankAccount

protected BankAccount(int initialBalance,
                      Bank issuingBank)
               throws InsufficientFundsException
Construct a BankAccount with the given initial balance and issuing Bank. Construction counts as this BankAccount's first transaction.

Parameters:
initialBalance - the opening balance.
issuingBank - the bank that issued this account.
Throws:
InsufficientFundsException - when appropriate.
Method Detail

countTransaction

public void countTransaction()
                      throws InsufficientFundsException
Increment by 1 the count of transactions, for this account and for the issuing Bank. Does NOT count as a transaction.

Throws:
InsufficientFundsException - when appropriate.

deposit

public int deposit(int amount)
            throws InsufficientFundsException
Deposit the given amount, increasing this BankAccount's balance and the issuing Bank's balance. Counts as a transaction.

Parameters:
amount - the amount to be deposited
Returns:
amount deposited
Throws:
InsufficientFundsException - when appropriate.

getBalance

public int getBalance()
Get the current balance. Does NOT count as a transaction.

Returns:
current account balance

getIssuingBank

protected Bank getIssuingBank()
The bank that issued this account.

Returns:
the Bank.

getTransactionCount

public int getTransactionCount()
Get the number of transactions performed by this account. Does NOT count as a transaction.

Returns:
number of transactions performed.

getTransactionFee

protected int getTransactionFee()
Get transaction fee. By default, 0. Override this for accounts having transaction fees.

Returns:
the fee.

incrementBalance

public final void incrementBalance(int amount)
                            throws InsufficientFundsException
Increment account balance by given amount. Also increment issuing Bank's balance. Does NOT count as a transaction.

Parameters:
amount - the amount of the increment.
Throws:
InsufficientFundsException - when appropriate.

newMonth

public abstract void newMonth()
                       throws InsufficientFundsException
Action to take when a new month starts.

Throws:
InsufficientFundsException - thrown when funds on hand are not enough to cover the fees.

requestBalance

public int requestBalance()
                   throws InsufficientFundsException
Request for balance. Counts as a transaction.

Returns:
current account balance.
Throws:
InsufficientFundsException - when appropriate.

withdraw

public int withdraw(int amount)
             throws InsufficientFundsException
Withdraw the given amount, decreasing this BankAccount's balance and the issuing Bank's balance. Counts as a transaction.

Parameters:
amount - the amount to be withdrawn
Returns:
amount withdrawn
Throws:
InsufficientFundsException - when appropriate.