Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following BankAccount class: // A bank account has a balance that can be changed by deposits and withdrawals. public class BankAccount { private

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); } }

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

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago