Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Intro to JAVA thanks! CODE: import java.util.Arrays; public class Bank { // Your work goes here. public String toString() { String r = ; for
Intro to JAVA thanks!
CODE: import java.util.Arrays; public class Bank { // Your work goes here. public String toString() { String r = ""; for (int i = 0 ; i
THE BANKACCOUNT CLASS:
The BankAccount class is given. Also, The BankTester class is given for you to test your Bank class. Do not change these given classes.
public class BankAccount { private double balance; public BankAccount (double initialBalance) { balance = initialBalance; } public double getBalance() { return balance; } public String toString() { return balance + " "; } } public class BankTester { public static void main (String[] args) { Bank bank = new Bank(5); bank.add(new BankAccount(100)); bank.add(new BankAccount(70)); bank.add(new BankAccount(50)); bank.add(new BankAccount(200)); bank.add(new BankAccount(150)); /* If your add method fails to grow the array, * the following add will be an error. * If you cannot make it to grow, comment out * the following add to proceed to the next test cases. */ bank.add(new BankAccount(800)); System.out.println(bank.toString()); // 100.0 70.0 50.0 200.0 150.0 800.0 System.out.println(bank.minPos()); // 2 bank.remove(-1); // Invalid index bank.remove(bank.size()); // Invalid index bank.remove(3); System.out.println(bank.toString()); //100.0 70.0 50.0 800.0 150.0 } }Finish the Bank class which manages BankAccount objects. The Bank class defines e an instance variable accounts of which type is BankAccount[]. It also defines a companion variable of the array called accountSize. The accountSize means two things: the number of BankAccount objects stored in the array and the index of the next empty slot of the array * a constructor that takes a capacity and initializes the instance variable accounts with the reference of an array object with the capacity e following methods (Read instructions carefully.) o public void add(BankAccount ba) This mutator takes a BankAccount object and adds it to the array accounts. It first checks if the array currently has enough space to accommodate the incoming BankAccount object. If not, it doubles the capacity of the array accounts. Under any circumstances, the method should be able to add the parameter BankAccount object to the array accounts. o public int size0 o public int minPosO o public void remove(int pos) This accessor returns the number of BankAccount objects stored in this Bank. This accessor finds a BankAccount with the minimum balance and returns its position. This mutator removes a BankAccount object from the position pos of the array accounts. Note that the array is not ordered. If pos is not a valid index, the method doesn't remove anything, but prints an error message "Invalid index o public double getAverageBalance0 This accessor returns the average of the balances of all BankAccount objects in the array. o The toString method is given. It returns a string representation of the array accounts
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