Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Goals: Write Classes To Generate Exceptions When Detecting Errors. Write A Program To Handle Exceptions. Program: Develop A Program That Tests An Object Of The

Goals: Write Classes To Generate Exceptions When Detecting Errors. Write A Program To Handle Exceptions. Program: Develop A Program That Tests An Object Of The Bank That Has A List Of BankAccount Objects. The Program Should Support The Following Operations: Create A Bank Object. Provide A Menu For The User To: O Add A New BankAccount To The Bank. O Get

Java Programming Question * URGENT *

Here is a Java BankAccount class code: (which we need to modify it and complete the implementation ):

public class BankAccount {

private double balance;

private int accountNumber;

public BankAccount(int anAccountNumber){

balance = 0;

accountNumber = anAccountNumber;

}

public BankAccount(int anAccountNumber, double initialBalance){

balance = initialBalance;

accountNumber = anAccountNumber;

}

public double getBalance() {

return balance;

}

public int getAccountNumber(){

return accountNumber;

}

public void deposit(double amount){

balance += amount;

}

public void withdraw(double amount){

balance -= amount;

}

@Override

public String toString(){

return "Account Number: " + accountNumber + " balance: " + balance;

}

}

Here is a Java Bank class code: (which we need to modify it ):

import java.util.ArrayList;

public class Bank {

private ArrayList accounts;

public Bank()

{

accounts = new ArrayList();

}

public void addAccount(BankAccount a)

{

accounts.add(a);

}

public double getTotalBalance()

{

double total = 0;

for(BankAccount a : accounts)

{

total = total + a.getBalance();

}

return total;

}

/**

Counts the number of bank accounts whose balance is at least a given value.

@param atLeast the balance required to count an account

@return the number of accounts having least the given balance

*/

public int count(double atLeast)

{

int matches = 0;

for(BankAccount a : accounts)

{

if (a.getBalance() >= atLeast)

matches++;

}

return matches;

}

/**

Finds a bank account with a given number.

@param accountNumber the number to find

@return the account with the given number, or null if there is no such account

*/

public BankAccount find(int accountNumber)

{

for(BankAccount a : accounts)

{

if (a.getAccountNumber() == accountNumber)

return a;

}

return null;

}

/**

Gets the bank account with the largest balance.

@return the account with the largest balance, or null if the bank has no accounts

*/

public BankAccount getMaximum()

{

if (accounts.size() == 0)

return null;

BankAccount largest = accounts.get(0);

for (int i = 1; i

{

BankAccount a = accounts.get(i);

if (a.getBalance() > largest.getBalance())

largest = a;

}

return largest;

}

public String toString()

{

return "Bank " + accounts.toString();

}

}

Here is a Java BankAccountException code:

public class BankAccountException extends RuntimeException

{

public BankAccountException(){}

public BankAccountException(String message){

super(message);

}

}

Here is a Java BankException code:

public class BankException extends RuntimeException

{

public BankException(){ }

public BankException(String message){

super(message);

}

}

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

Combinatorial Testing In Cloud Computing

Authors: Wei-Tek Tsai ,Guanqiu Qi

1st Edition

9811044805, 978-9811044809

Students also viewed these Programming questions

Question

=+d) Why does the no trend model from Exercise 40 no longer work?

Answered: 1 week ago

Question

Calculate E[X] if X is a Poisson random variable with parameter .

Answered: 1 week ago