Click to reopen instructions.

For this test you need to write four classes as described in each problem. You will not be able to compile your code in this environment and there are no unit tests—I will be grading it based on how you structure the classes and whether you use various features of inheritance properly. Minor syntax errors will not lose you points. (This is similar to the AP exam and the College Board FRQ tests except that the code editor here is a lot better.)

If you need to you can go back to earlier problems to revise your code to fit better with the classes decribed later in the test.

Questions of

Write a Bank class. Objects of this class represent a bank as a whole, i.e. the business that maintains accounts for lots of different people.

A bank object is responsible for handing out new account numbers when needed via the getNextAccountNumber method. (Each time it is called this method should return a new int value that hasn't been returned before.) It also should have a method addAccount that takes an Account (see next question) argument and a findAccount method that takes an account number and returns the Account object representing that account. (This implies that the bank class will have some instance variable that it uses to keep track of all the accounts.) The bank will also have its own main Account which it uses to collect fees and which can be obtained via the getMainAccount method.

Write a class Account to represent a bank account.

Every account should have an int account number and an int balance (in pennies). Those values thould be private but there should be getter methods getAccountNumber and getBalance to obtain them.

All accounts are constructed by being passed a Bank object as well as whatever other arguments needed to initialize the specific kind of account. Every account should set its account number when it is constructed, getting the value from the Bank object via the getNextAccountNumber method. And every account should be added to the Bank using the bank's addAccount method when it is constructed.

All accounts should also have three methods for modifying the account balance: deposit which takes an int amount and adds it to the balance, withdraw which takes an int amount and subtracts it from the balance and transferTo that takes an int amount and another account and withdraws the amount from the current account and deposits it in the argument account. The other account can be any kind of account.

Write a class SavingsAccount which represents specifically a savings account. In addition to everything a normal account has, savings accounts are constructed with a double interest rate and have a computeInterest method that takes no arguments and returns an int amount of interest earned, computed by multiplying the current balance by the accounts interest rate.

Write a class CheckingAccount which represents specifically a checking account. In this bank, in addition to everything a normal account has, checking accounts are constructed with an int balance inquiry fee and every time the balance is requested via the getBalance method, the amount of that fee should be transferred from the checking account to the Bank’s main account, obtained via the getMainAccount method before returning the balance after the fee has been deducted.