Question
Use the Java Class, Account.java , provided. import java.util.Date; public class Account { private int id; private double balance; private Date dateCreated; private static int
Use the Java Class, Account.java, provided.
import java.util.Date;
public class Account {
private int id;
private double balance;
private Date dateCreated;
private static int nextId = 1;
public Account(double balance)
{
id = nextId;
this.balance = balance;
nextId++;
dateCreated = new Date();
}
public int getId()
{
return id;
}
public double getBalance()
{
return balance;
}
public Date getDateCreated()
{
return dateCreated;
}
public void withdraw( double amount )
{
balance -= amount;
}
public void deposit( double amount )
{
balance += amount;
}
public String toString()
{
return "Account ID: " + id +
" Balance: " + balance +
" Date Created " + dateCreated;
}
}
Write a Java Program that meets the following requirements:
Write a Java class, Bank
At the beginning of the program, include a comment with your name and a brief description of the program. Please include a short comment before each
The Bank class will have the following instance variables:
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
The Bank class will have the following constructor:
A default/noargs constructor:
It will create the Array of Account objects
Set the numberOfAccounts to zero
One accessor method:
public int getNumberOfAccounts() //returns the numberOfAccounts
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
A toString() method that returns a String representation of the Bank object in the format shown in the sample output below.
public String toString()
Write a test program, TestBank.java
Create a Bank object
In a loop, repeat 5 times:
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 use either of the two addAccount methods of the Bank class to accomplish this.
At the end of the loop, print the Bank object.
Using the methods of the Bank class, print the following in the format shown in the sample running below:
The total balance of all accounts in the Bank using the
getTotalBalance() method of the Bank class
The Account with the highest balance in the array of Accounts using the
getMaxBalance() method of the Bank class.
The prompts and output should be formatted like the sample program running below.
Readability and indentation: Code should be easy to read and properly indented. Variable names should be descriptive.
Sample Program running
Enter a balance 100
Enter a balance 200
Enter a balance 300
Enter a balance 400
Enter a balance 500
The accounts in the Bank are:
Account ID: 1 Balance: 100.0 Date Created Sun Mar 20 10:18:17 EDT 2016
Account ID: 2 Balance: 200.0 Date Created Sun Mar 20 10:18:18 EDT 2016
Account ID: 3 Balance: 300.0 Date Created Sun Mar 20 10:18:19 EDT 2016
Account ID: 4 Balance: 400.0 Date Created Sun Mar 20 10:18:20 EDT 2016
Account ID: 5 Balance: 500.0 Date Created Sun Mar 20 10:18:22 EDT 2016
The total balance in the bank is 1500.0
The account with the highest balance in the bank is
Account ID: 5 Balance: 500.0 Date Created Sun Mar 20 10:18:22 EDT 2016
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started