Lab Assignment - Inheritance & Sorting          12/1/06

Topics: Chapter 8

To get Started:

1. Download the two files: TestAccount.java and Accounts.java  from the web site at  http://www.public.asu.edu/~navabi/CHS.html . Study the files..

2. Create a new class, SavingAccount  which inherits variables and methods of its super-class, Account.  

 In a saving account, the account holder promises to leave the money in the account for some number of years, for a higher interest rate. Class SavingAccount has added instance variables, interestRate ( type double), and maturity of the account (type int).  The interest rate and the maturity of the account for each account are specified in the file. The penalty for withdrawing before maturity is $30.00.

Hint: For the SavingAccount class, the withdraw overrides the withdraw in class Account by withdrawing the specified amount plus the penalty only if the maturity of the account is not over. Overrides the withdrawal method, but uses it to perform the actual withdrawal operation.

Also override the addInterest method (adds the yearly  interest and  subtracts a year from the maturity)  and the toString methods from class Account.

3.  Download the file  accounts2.txt , which keeps a database of accounts. It includes the account's  name,  id, and balance. If the account is a Saving Account, the line in the file includes also the interest rate and the maturity of the account. Use the count token to instantiate an account or a saving account.

4. Add the following options to the main menu in the  file TestAccount.java:

  'w': this option asks for the  account name and then withdraws the specified amount from the account. It prints the new balance.

Sample Output:

Please enter a command or type "?" to see the menu:
d
112233 Smith $40,000.00
6677567 Johnson $5,000.00
665544 Jones $6,580.00 0.042 5
786234 Wiley $70,000.00
9873890 Kamin $30,000.00 0.045 6
23456 Andy $34,500.00
65555 Loftus $8,760.00 0.04 4
4578390 Lewis $435,600.00
876539 Ceasor $400,000.00

Please enter a command or type "?" to see the menu:
?
d: Display all accounts
s: Sort all accounts by names
a: Add interest
w: withdrawal
t: Transfer
?: Help menu
q: Stop the program

Please enter a command or type "?" to see the menu:
a

112233 Smith $41,400.00
6677567 Johnson $5,175.00
665544 Jones $6,856.36 0.042 4
786234 Wiley $72,450.00
9873890 Kamin $31,350.00 0.045 5
23456 Andy $35,707.50
65555 Loftus $9,110.40 0.04 3
4578390 Lewis $450,846.00
876539 Ceasor $414,000.00
***Yearly interest is added to accounts****

Please enter a command or type "?" to see the menu:
w
Which account withdrawing from?
Jones
Amount withdrawal:
800
665544 Jones $6,024.36 0.042 4

Please enter a command or type "?" to see the menu:
q

Note: Use the following Coding Guidelines:

*******************************************************************************