Assignment Two


For this assignment you are to write a separate (once again do not change the BankAccount class) Java main class to read data from a file and process transactions for various BankAccount customers. Use the BankAccount.java class from Assignment One. (Make sure you copy the file into your src folder). The data file is bankData.txt. (Make sure you copy the data file into the parent folder of the src folder). Each line of the data file is of the following form:

anAccountNumber aTransaction anAmount

For example:

123456789 deposit 1000.00


The main class should read the data file using the Scanner class and keep BankAccount objects in an ArrayList<BankAccount> variable. As each line is read either update an account in the ArrayList<BankAccount> variable or add a new account to the ArrayList<BankAcount> variable. (See the ArrayList and Scanner examples on the examples page). You can assume that there are no errors in the data file. After the accountNumber is extracted use it to construct a BankAccount object and assign it to a BankAccount variable. Use the indexOf(..) method of the ArrayList<BankAccount> class to search the ArrayList for a BankAccount object that matches the BankAcount variable. (The indexOf(..) method of the ArrayList class works exactly like the indexOf(..) method of the String class). If a match is found then get the one from the ArrayList and assign it into the BankAccount variable replacing it's value. If a match is not found then add the variable to the ArrayList. Finally update the variable according to the transaction code and the amount.

After processing the file display the ArrayList<BankAccount> in a JOptionPane window. Sort the ArrayList<BankAccount> using the Collections class (static) sort method and display the ArrayList<BankAccount> in a JOptionPane window again.

This assignment is due October 3rd at the beginning of class.