given the above bankaccount class, what is the output of the following program /
ID: 3697504 • Letter: G
Question
given the above bankaccount class, what is the output of the following program / Test class BankAccount ublic class TestBankAccount public static void main (String I args) 1 = new BankAccount("Amy", 1000.0); System.out.printin(acct1.getBalance)) Bankaccount acet - new BankAccount(" Mike, 550.00): BankAccount acct2= new BankAccount("Mike", 550.00); System.out.printin(acct2.getBalance())i accti.withdraw(250.00) acct2.withdraw(250.00); acct2.deposit(250.00) System.out.printin(acct1.getBalance)); System.out.printin(acct2.getBalance)); acct1.deposit(100.00) accti.deposit(50.00); accti.deposit(100.00); acct2.withdraw(50.0); acct2.deposit(250.00); System.out.printin(acct1.getBalance()): System.cut mntnfacth,oetbalance(0) System.out.printin(acct1); System.out.printin(acct1.getBalance)); System.out.printin(acct2)Explanation / Answer
Here is the code explained, along with the screenshot for you:
//Test class BankAccount.
public class TestBankAccount
{
public static void main(String[] args)
{
BankAccount acct1 = new BankAccount("Amy", 1000.0); //Creates a new account with Account name Amy, and balance 1000.00
System.out.println(acct1.getBalance()); //This will print the balance: 1000.00
BankAccount acct2 = new BankAccount("Mike", 550.00); //Creates a new account with Account name Mike, and balance 550.00
System.out.println(acct2.getBalance()); //This will print the balance: 550.00
acct1.withdraw(250.00); //Withdraws an amount of 250.00 from available balance. So, balance is: 750.00
acct2.withdraw(250.00); //Withdraws an amount of 250.00 from available balance. So, balance is: 200.00
acct2.deposit(250.00); //Deposits an amount of 250.00 to available balance. So, balance is: 550.00
System.out.println(acct1.getBalance()); //This will print the balance: 750.00
System.out.println(acct2.getBalance()); //This will print the balance: 550.00
acct1.deposit(100.00); //Deposits an amount of 100.00 to available balance. So, balance is: 850.00
acct1.deposit(50.00); //Deposits an amount of 50.00 to available balance. So, balance is: 900.00
acct1.deposit(100.00); //Deposits an amount of 100.00 to available balance. So, balance is: 1000.00
acct2.withdraw(50.00); //Withdraws an amount of 50.00 from available balance. So, balance is: 500.00
acct2.deposit(250.00); //Deposits an amount of 250.00 to available balance. So, balance is: 750.00
System.out.println(acct1.getBalance()); //This will print the balance: 1000.00
System.out.println(acct1); //This will print the name along with balance: Amy 1000.00
System.out.println(acct1.getBalance()); //This will print the balance: 750.00
System.out.println(acct2); //This will print the name along with balance: Mike 750.00
}
}
//So, the output of this code is:
//1000.00
//550.00
//750.00
//550.00
//1000.00
//Amy 1000.00
//750.00
//Mike 750.00
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.