Question: Use the Java Class, Account.java, provided. Please do not rename or make any changes to this class. Do not turn in the Account class. Your
Use the Java Class, Account.java, provided. Please do not rename or make any changes to this class. Do not turn in the Account class. Your program will be tested with the Account class provided.
The Bank class will have the following instance variables: (5points)
An Array of Account objects that can hold 20 Accounts named, bank.
An int variable, numberOfAccounts which indicates the number of Account
objects in the account array
2. The Bank class will have the following constructor:
A defaulto args constructor: (5 points)
It will create the Array of Account objects
Set the numberOfAccounts to zero
One accessor method: (5 points)
public int getNumberOfAccounts() //returns the numberOfAccounts
The following methods:
public void addAccount (Account a) (5 points)
Adds Account a to the Array of accounts
Adds 1 to the numberOfAccounts public void addAccount(double initBalance) (5 points)
Creates a new Account using initBalance
Adds the new Account to the Array of accounts Adds 1 to the numberOfAccounts
public double getTotalBalance() (7.5 points) Returns the sum of the balance of all the Account objects in the Array of accounts
public Account getMaxBalance() (7.5 points) 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. (10 points)
public String toString() 3. Write a test program
which does the following:
Create a Bank object (5 points)
In a loop, repeat 5 times: (10 points)
Using a Scanner, prompt the user for the balance of an Account object.
Call the addAccount method of the Bank to add an Account object to the Array using the balance entered by the user. You can call either of the two addAccount methods of the Bank class.
At the end of the loop, print the Bank object. (5 points)
Using the methods of the Bank class, print the following in the format shown below:
The total balance of all accounts in the Bank using the getTotalBalance() method of the Bank class (5 points)
The Account with the highest balance in the array of Accounts using the getMaxBalance() method of the Bank class. (5 points)
The prompts and output should beformattedlikethesampleprogramrunning below. (5 points)

import Java.util. /This class represents an Account. /An Account has: /An account id /A balance /A date created /The static field, account Number is used to assign each account an accountid starting with 1. public class Account i private int accountId; private double balance; private Date date created; private static int accountNumber = 1; 1 Default counstructor. Creates object with a balance of o public Account ) i date, created = new Date(); balance = 0; account!d = accountNumber; accountNumber+i //Create an account with an initial balance public Account (double balance) i date, created = new Date(); this. balance = balance; account!d = accountNumber; accountNumber+i /Getters for each instance field belo public int getAccountid ) i return accountid; public double getBalance ) i return balance; public Date getDatecreated ()1 return date created; //setters withdraw and deposit change the balance //setters are not required for the dateCreated and accountId fields //since the fields cannot be changed public void withdraw (double amount) i balance-= amount; public void deposit (double amount) i amount; balance //This method returns a String representation of the Account object public String tostring ) i return Account Id: accountidBalance balanceDate Created:+date created
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
