Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1: Write a sample program implements a Bank class that stores an array list of bank accounts. a. This section you will add accounts

Question 1: Write a sample program implements a Bank class that stores an array list of bank accounts. a. This section you will add accounts package com.company; import java.util.ArrayList; /** This bank contains a collection of bank accounts. */ public class Bank { /** This bank contains a collection of bank accounts */ public Bank() accounts =new ArrayList(); /** *Adds an account to this bank * @param a the account to add */ public void addAccount a) { // write your code here } b. You will write a code for sum of balances /** *Get the sum of the balances of all accounts in this bank. @return the sum of the balances */ public double getTotalBalance(){ double total =0; for(BankAccount a :accounts) { // write your code here } return total; } c. in his section you will complete the code for least balance /** *Counts the number of bank accounts whose balance is at least a given value. @param arLeast the balance required to count an account @return the number of accounts having at least the given balance */ public int count(double atLeast) for (BankAccount a : accounts) { //if statement to validate the match } return matches; D. Find the account with given number /** *Find bank account with a given number. @param accountNumber the given 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)//Found a match //write code here } // write code here if No match in the entire array list } e. In this section you will find account with largest balance /** Get 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 largestYet =account.get(0); for (int i =1; i< accounts.size(); i++) { //write code here largest balance } return largestYet; } private ArrayListaccounts;

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions