Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java Program that meets the following requirements: 1. Write a Java class, XXXX_Bank, where XXXX where XXX is your Kean email id. (5

Write a Java Program that meets the following requirements:

1. Write a Java class, XXXX_Bank, where XXXX where XXX is your Kean email id. (5 points) 2. 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 method (5 points) 3. The Bank class will have the following instance variables: ( 5 points) a. 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 2. The Bank class will have the following constructor: a. A default/noargs constructor: (5 points) i. It will create the Array of Account objects ii. Set the numberOfAccounts to zero b. One accessor method: (5 points) public int getNumberOfAccounts() //returns the numberOfAccounts c. The following methods: public void addAccount (Account a) (5 points) x Adds Account a to the Array of accounts x Adds 1 to the numberOfAccounts public void addAccount(double initBalance) (5 points) x Creates a new Account using initBalance x Adds the new Account to the Array of accounts x Adds 1 to the numberOfAccounts public double getTotalBalance() (7.5 points) x Returns the sum of the balance of all the Account objects in the Array of accounts public Account getMaxBalance() (7.5 points) x 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, XXXX_TestBank.java where where XXX is your Kean email id which does the following: a. Create a Bank object (5 points) b. In a loop, repeat 5 times: (10 points) 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 call either of the two addAccount methods of the Bank class. c. At the end of the loop, print the Bank object. (5 points) d. Using the methods of the Bank class, print the following in the format shown below: i. The total balance of all accounts in the Bank using the getTotalBalance() method of the Bank class (5 points) ii. The Account with the highest balance in the array of Accounts using the getMaxBalance() method of the Bank class. (5 points) e. The prompts and output should be formatted like the sample program running below. (5 points) f. Readability and indentation: Code should be easy to read and properly indented. Variable names should be descriptive. (5 points) 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 Requirement Points possible Points earned Name of both classes start with XXXX as required 5 Comments at beginning of class including student name and before each method 5 Instance variables of Bank 5 Constructor of Bank 5 getNumberOfAccounts 5 addAccount(Account a) 5 addAccount (double initialBalance) 5 getTotalBalance() 7.5 getMaxBalance() 7.5 toString method of Bank 10 Create a Bank Object 5 Loop to get info and add Account objects 10 Printing the Bank Object 5 Using getTotalBalance() 5 Using getMaxBalance() 5 Prompts and outputs as in sample 5 Readability and indentation 5 Total Points earned 100

Here is code for Account.java

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 { private int accountId; private double balance; private Date date_created; private static int accountNumber = 1;

// Default counstructor. Creates object with a balance of 0 public Account () { date_created = new Date(); balance = 0; accountId = accountNumber; accountNumber++; } //Create an account with an initial balance public Account (double balance) { date_created = new Date(); this.balance = balance; accountId = accountNumber; accountNumber++; } //Getters for each instance field below: public int getAccountId () { return accountId; }

public double getBalance () { return balance; }

public Date getDateCreated () { 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) { balance -= amount; }

public void deposit (double amount) { balance += amount; } //This method returns a String representation of the Account object public String toString () { return "Account Id: " + accountId + " Balance: " + balance + " Date Created: " + date_created; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 10th International Symposium Sstd 2007 Boston Ma Usa July 2007 Proceedings Lncs 4605

Authors: Dimitris Papadias ,Donghui Zhang ,George Kollios

2007th Edition

3540735399, 978-3540735397

More Books

Students also viewed these Databases questions