Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following BankAccount class: // A bank account has a balance that c

ID: 3860384 • Letter: C

Question

Consider the following BankAccount class:

// A bank account has a balance that can be changed by deposits and withdrawals.
public class BankAccount {
   private double balance;
   private String holder;

   // Constructor method
   public BankAccount(String holderName, double initialBalance){
      holder = holderName;
      balance = initialBalance; }

   public void deposit(double amount){ balance = balance + amount;}

   public void withdraw(double amount){
      if(amount <= balance)
         balance = balance - amount;
      else System.out.println("No sufficient Funds."); }
   
   public double getBalance(){ return balance;}
   public String getHolder(){ return holder;}
   public String toString(){return (getHolder() + " has " + getBalance() + " dollars."); }
}

Given the above BankAccount class, write in the box the exact output of the following test program.

// Test class BankAccount.
public class TestBankAccount
{
public static void main (String [] args)
{
    BankAccount acct1 = new BankAccount("Amy",2500.0);
    System.out.println(acct1.getBalance());
    BankAccount acct2 = new BankAccount("Mike",5000.00);
    System.out.println(acct2.getBalance());
    acct1.withdraw(500.00);
    acct2.withdraw(250.00);
    acct2.deposit(250.00);
    System.out.println(acct1.getBalance());
    System.out.println(acct2.getBalance());
    acct1.deposit(1000.00);  
    acct1.deposit(5000.00);   
    acct1.deposit(1000.00);  
    acct2.withdraw(5000.0);
    acct2.deposit(1000.00);
    System.out.println(acct1.getBalance());
    System.out.println(acct1);
    System.out.println(acct2.getBalance());
    System.out.println(acct2);
}
}

Explanation / Answer

Output:

Note: "//" Part is explaination

2500.0 // intial balance print acct1
5000.0 //inital balance print
2000.0 // withdraw 500 from acct1
5000.0 //withdraw 250 from acct2 and deposit 250 to acct2 so no change
9000.0 // deposit 1000,5000,1000 to acct1 = 7000 + 2000 = 9000
Amy has 9000.0 dollars
1000.0 // withdraw 5000 and deposit 1000 , so total amount =1000
Mike has 1000.0 dollars

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote