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

This Exercise includes two classes, AccountTest and Account . The AccountTest cl

ID: 3722779 • Letter: T

Question

This Exercise includes two classes, AccountTest and Account. The AccountTest class should create a new Account with a starting balance of $100. Then it should have a do -- while() loop that asks if the user wants to enter a deposit "D" or withdrawal "W" or end "Quit" Based on the user's input, the transacton should take place and then return to ask the user to enter another transaction.  

The Account class is very similar to the Savings class created in the last exercise. The format of the output from the getStatement() does not have to be columnar but I encourage you to try.

When a user chooses "Quit", the program should display the current balance and give a statement of all of the transactions.  

Example Input Request
For a deposit Enter: D
Withdrawal Enter: W  
or 'Quit' to exit.

Example Output
The current balance is $ 262.92
Transaction History
Deposit 673.88 Balance $773.88  
Withdrawal 159.44 Balance $614.44  
Deposit 592.45 Balance $1206.89  
Deposit 22.54 Balance $1229.43  
Withdrawal 966.51 Balance $262.92

import java.util.*;
/**
*
* @author Student
*/
public class AccountTest {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);

// enter AccountTest code here

} // end AccountTest class

//*************************************************
//** Account class starts below this box **
//*************************************************

class Account {

// Enter Account class code here

} // end Account class

Explanation / Answer

AccountTest.java

import java.util.Scanner;

public class AccountTest {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

Account acc = new Account(100);

String choice = "";

do {

System.out.println("Choose Option: D. Deposit W. Withdrawal Quit: Quit Enter your choice: ");

choice = input.next();

if(!choice.equalsIgnoreCase("quit")) {

System.out.println("Enter the amount:");

double amt = input.nextDouble();

if(choice.equalsIgnoreCase("D")) {

acc.deposit(amt);

} else if(choice.equalsIgnoreCase("W")) {

acc.withdrawal(amt);

}

}

} while(!choice.equalsIgnoreCase("quit"));

System.out.println(acc.getStatement());

// enter AccountTest code here

}

} // end AccountTest class

Account.java

public class Account {

private double balance;

private String history="Transaction History";

public Account(double balance) {

this.balance=balance;

}

public void deposit(double b) {

balance+=b;

history= history+" Deposit "+b+" Balance "+balance;

}

public void withdrawal(double b) {

balance-=b;

history= history+" Withdrawal "+b+" Balance "+balance;

}

public String getStatement() {

return "The current balance is $ "+balance+" "+history;

}

}

Output:

Choose Option:
D. Deposit W. Withdrawal Quit: Quit
Enter your choice:
D
Enter the amount:
1000
Choose Option:
D. Deposit W. Withdrawal Quit: Quit
Enter your choice:
W
Enter the amount:
500
Choose Option:
D. Deposit W. Withdrawal Quit: Quit
Enter your choice:
quit
The current balance is $ 600.0
Transaction History
Deposit 1000.0 Balance 1100.0
Withdrawal 500.0 Balance 600.0

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