Professor I. Rudowsky                                                 CIS 26MW12

Homework #6                                                       Due Nov 8, 2004

Write a class named BankAccount that has instance variables : String acctName, int acctID, Date birthDate and double balance. It also contains a static variable, int numAccts initialized to 0, which will be used to keep track of how many BankAccount objects have been created.

 

Write the class Date which is composed of the following instance variables: int month, int day, and int year all private. Write a constructor that accepts Date as a parameter, a constructor that accepts 3 integers (representing month, day and year) as parameters, a toString() method that returns a String in the format dd-mmm-yyyy” (where dd is the day of the month, mmm is a three letter abbreviation for the month name and yyyy is the year) and any get, set or other methods you may need.

 

The constructor BankAccount will take parameters (name, balance and Date) and initialize those instance variables of that object. To pass Date to the constructor use new Date(m,d,yyyy) as the argument. The constructor will increment numAccts and assign its value to acctID.

 

Write a method toString() which will return a String containing the account number, name, birthdate and balance formatted with a description for each variable such as

 

Account 1 of Joe Riveria birthdate 15-Feb-1982 has a balance of $3,278.98

 

Use the Currency format to display the balance.

 

In the driver program BankAccountTest you will read input from the console or via JOptionPane. Enter at least three records containing name, balance, month, day and year each record on one line of input separated by blanks. Tokenize the input - convert a token to double using Double.parseDouble(String) and to integer with Integer.parseInt(String).

 

Using an array of BankAccount objects named acct, instantiate the first object into acct[0] using the five tokenized values as arguments for the constructor. Continue to loop and instantiate the remaining objects.

 

When all records have been read in (three is fine), loop through the array and print each object using the toString() method of BankAccount. Also, compute and print the average age and balance of all the account holders you read in.

 

Define any additional methods or variables you need in either class.