Question: The Bank class will have the following instance variables: . An Array of Account objects that can hold 20 Accounts named, bank. b. An int
The Bank class will have the following instance variables: . An Array of Account objects that can hold 20 Accounts named, bank. b. An int variable, numberOfAccounts which indicates the number of Account objects in the account array The Bank class will have the following constructor: a. A default/noargs constructor: i. It will create the Array of Account objects ii. Set the numberOfAccounts to zero b. One accessor method: public int getNumberOfAccounts() //returns the numberOfAccounts c. The following methods: public void addAccount (Account a) Adds Account a to the Array of accounts Adds 1 to the numberOfAccounts public void addAccount(double initBalance) Creates a new Account using initBalance Adds the new Account to the Array of accounts Adds 1 to the numberOfAccounts public double getTotalBalance() Returns the sum of the balance of all the Account objects in the Array of accounts public Account getMaxBalance() Returns the Account with the highest balance in the Array of accounts d. A toString() method that returns a String representation of the Bank object in the format shown in the sample output below. public String toString() 3. Write a test program,TestBank.java a. Create a Bank object b. In a loop, repeat 5 times: i. Using a Scanner, prompt the user for the balance of an Account object. ii. Call the addAccount method of the Bank to add an Account object to the Array using the balance entered by the user. You can use either of the two addAccount methods of the Bank class to accomplish this. c. At the end of the loop, print the Bank object. d. Using the methods of the Bank class, print the following in the format shown in the sample running below: i. The total balance of all accounts in the Bank using the getTotalBalance() method of the Bank class ii. The Account with the highest balance in the array of Accounts using the getMaxBalance() method of the Bank class. e. The prompts and output should be formatted like the sample program running below. f. Readability and indentation: Code should be easy to read and properly indented. Variable names should be descriptive.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
