ITEC 120 LAB 20 Back to Lab index page

A Flexible Account Class

File Account.java contains a definition for a simple bank account class with methods to withdraw, deposit, get the balance and account number, and return a String representation. Note that the constructor for this class creates a random account number. Save this class to your directory and study it to see how it works. Then modify it as follows:

1. Overload the constructor as follows:

2. Overload the withdraw method with one that also takes a fee and deducts that fee from the account.

File TestAccount.java contains a simple program that exercises these methods. Save it to your directory, study it to see what it does, and use it to test your modified Account class.

Suppose the bank wants to keep track of how many accounts exist. Add a static variable to the Account class to keep track of how many accounts get created. Where will you need to increment this variable?

Add a static getter for that variable to the Account class. In your driver, call the method and print out a statement to show how many accounts exist.