Assignment #5, CS 49J, Section 1

due October 16, 2007
70 points

Define a Bank class and two classes InterestBearingAccount and NonInterestBearingAccountfor bank accounts, that work as described below. Test your class using the main method of the BankTester class that's available as the additional file for Assignment 5 on the class web site. Turn in the results of this test, along with hard and soft copies of your class definitions.

The Bank class is to maintain an interest rate, and a collection of bank accounts. Accounts may be interest bearing, or not interest bearing. The class is to have a method payInterest that updates the balance of each vested interest-bearing account by incrementing the balance at the current interest rate. So for example if the interest rate is 0.05 and a vested interest-bearing account has balance 1000.0, then the payInterestmethod should increase this balance to 1050.0.

An interest-bearing account becomes vested at the end of the first invocation of the payInterest method after its creation. The idea here is that if, say, interest is paid once a year, an account cannot receive a full year's interest if it has not been in existence for a year.

The intial interest rate is to be the only argument of the class's constructor. It is to be represented as a double, so that, for example, the value 0.05 represents a 5% interest rate. You don't need to provide an explicit zero-argument constructor for the class if your interest rate for the class has a default value of 0.

Other methods that are to be part of the Bank class are

Note that each of the above methods is invoked in the BankTester class. Also note that it is allowed for a checking account and a savings account to have the same account name. And note that there is no notion of deposit to an account, or withdrawal from an account.

Each of the two account classes is to have two constructors. The first constructor takes as its only argument a String reprsenting the account name, and initializes the account balance to 0 and the account name to the given name. The second constructor takes a String and a double and initializes the account name to the given String and the initial account balance to the value given by the double. Each of the two classes is to have a double-valued method getBalance that returns the account balance. Each of the two classes is to have a String-valued method getName that returns the account name. Finally, the InterestBearingAccount is to have a payInterest method that takes an interest rate as argument (represented as a double, as described above), and increments the account by the fraction given by the interest rate (as described above).

You needn't worry about formatting the value of the payInterest method. You needn't check to see whether the initial balance of an account is nonnegative. You needn't check whether the initial balance consists of an even number of cents.

In Chapter 10, we will see how to use inheritance to simplify creation of multiple related classes. We will also see in later chapters how to invoke more efficient search and removal algorithms than sequential search (which is called linear search in Section 7.5.2).