Assignment Seven
Extending Your Classes

In this assignment you extend the functionality of your banking classes by creating a few subclasses.

Part One

Create a subclass of your BankAccount class named something like InterestBearingBankAccount. It should add an interest rate instance variable and a yearlyUpdate instance method. The yearlyUpdate method should calculate a year's worth of interest based on the current balance in the account and the interest rate for the account. The yearlyUpdate method should return the amount of interest added to the account.

Test this function appropriately in a main().

Part Two

Create a subclass of your Bank. The subclass should add an instance variable called interestPaid, and an instance method called endOfYear. This method should iterate through all the accounts in the bank, and if an account is an interest bearing account, the bank should call that account's yearlyUpdate method, and also track the amount of interest which the bank has paid out. The subclass should also add an instance method which creates an interest bearing account.

Your subclass should not make a new array to hold the interest bearing accounts! In order for your subclass to search through the array to locate the interest bearing accounts, it needs to have access to the array declared in your Bank class, so this array and the numberOfAccounts variable should be changed to protected from private.

Part Three

Create a main() method in a third class to demonstrate the abilities of your new classes. The method should create a bank and tell the bank to create a few accounts of each type (normal and interest-bearing). Conduct a few transactions with these accounts, and then call the endOfYear method on the Bank. The bank information summary method should be called periodically and the summary string displayed in order to show the state of the bank between these transactions as appropriate.

Part Four

Make sure that you have written proper JavaDoc comments for your classes.

What to turn in

You should turn in a copy of all your code (including the original classes and your new sub-classes) along with a printout of a run. This assignment is due at classtime on 13 April, 2007.