Bank and subclasses HashBank and TreeBank that behave as described below. You will also need a new class AccountHolder and the old classes BankAccount, SavingsAccount, and CheckingAccount. These classes are to behave as in Assignment 8, except that:
Bank class is to be an abstract class with two new methods. One is to be a nonabstract method getAccountHolders() with return type Set<AccountHolders>. It is to return the collection of account holders for all of the accounts in the bank. The second is to be an abstract method getSortedAccountHolders()
with return type List<AccountHolder>. Subclasses are to define this method to return a list of BankAccounts sorted by the (name of the) account holder.
Bank class is to represent its collection of accounts by a Map from an AccountHolder class to the BankAccount class. That is, the bank accounts are to be indexed by their account holders.
Bank class is to have a constructor that takes as its only argument an empty Map of AccountHolders to Bankaccounts. This Map argument is to serve as the initial collection of accounts (of whatever type) of the bank. If the argument to this constructor is not empty, the constructor is to throw an appropriate IllegalArgumentException. The TreeBank constructor is to invoke this constructor with an empty TreeMap as the first argument, and the HashBank constructor is to invoke this constructor with an empty HashMap as the first argument.
Bank class is not to have a getAccountNumber method. The Bank class methods removeAccount, deposit, withdraw, and getBalance are to take an AccountHolder object instead of an account number as their argument. Their definitions will of course have to be modified somewhat.
String argument as their first argument. This argument is to be used to construct an AccountHolder object as described for that class. These two methods are to throw IllegalArgumentExceptions with helpful error messages if they are given a negative initial balance, a negative interest rate, or a null string.
true if the collection of accounts was modified, and false otherwise.
TreeBank and HashBank classes are to have constructors that respectively pass an empty TreeMap and an empty HashMap to the superclass constructor. They are also to redefine getAccountHolders() so that the return value is respectively a TreeSet and a HashSet. Recall that they also need to redefine the abstract method getSortedAccountHolders().
BankAccount class, you are to replace the accountNumber instance variable by an accountHolder field, and replace the getAccountNumber by a getAccountHolder method. The equals method is to check whether two accounts have the same account holder (recall that we are assuming that no account holder can have more than one account).
BankAccount, CheckingAccount, and SavingsAccount constructors are to have no argument representing an account number.
AccountHolder is to have a constructor that takes a String as argument and a toString method that returns this string. The class is to implement the Comparable<AccountHolder> interface by comparing the string of one object with the string of another. The equals method of the class is to be redefined to be consistent with compareTo. The class is to redefine the hashValue method, using the value for its string.
For this assignment, you are to turn in hard and soft copies of your class definitions, as well as a hard copy of the results of testing with (the main method of) the class A9.java, available from the class web site. You may use (with appropriate credit) any code from the text, from your solution to Assignment 8, from my solution to Assignment 8, or from any earlier published solution to an Assignment 9. As always, you may add any additional methods or classes that you find useful.