Lab Exercise Nine
For this exercise do the following:
Download the class LabExerciseNine. LabExerciseNine is basically Assignment Four. It reads and processes the data file bankData.txt and adds account numbers to the ArrayList<String> accountNumbers and displays the summary of all accounts. I have commented the two calls to the new Bank class sort methods.
Modify the BankAccount class by overriding the equals and hashCode methods. (I will show this is class).
Modify the BankAccount class by implementing the Comparable<BankAccount> interface. Compare BankAccount objects by using their account numbers.
Now modify the Bank class by adding the methods public void sortAccountsByAccountNymber() and public void sortAccountsByBalance(). To implement the first method just use the Collections class to sort the ArrayList<BankAccount> accounts. Since you implemented the Comparable<BankAccount> interface the accounts will be sorted according to their account numbers. Check it by uncommenting the first sort call. For the second method implement the Comparator<BankAccount> interface in a class inside the Bank class so that the comparison is done on the balance field, high balances to low balances. Use the second form of the Collections sort method using an object of this class and uncomment the second sort statement. Now the bank accounts should be displayed in order from the largest balance to the lowest balance.