Question: Java Programming Question. I am trying to write a menu program with a starting balance of 1000$ and then after choosing a money amount and

Java Programming Question. I am trying to write a menu program with a starting balance of 1000$ and then after choosing a money amount and option to either deposit or withdraw, I want the total balance to be printe, but I want the previous balances to be added until the program is stopped. For example: if I enter 45 and D, the output should be 1045, and then when asked again, I enter 60 and W, the output should be 985. But I cannot figure out how to incorporate the previous balance and set the starting balance at 1000. My code is below.

import java.util.Scanner; public class ATM { public static void main(String[] args) { int result = 0, balance = 1000, money; char opt; Scanner sc = new Scanner(System.in);

Menu(); //function menu is called System.out.println("Enter money amount and ATM option"); money = sc.nextInt(); balance = sc.nextInt(); opt = sc.next().charAt(0); do { switch (opt) { case 'D': result = Deposit(balance, money);//call the function System.out.println("Balance = $" + result); break; case 'W': result = Withdrawal(balance, money); System.out.println("Balance = $" + result); break; } //switch System.out.println("Enter money amount and ATM option"); money = sc.nextInt(); balance = sc.nextInt(); opt = sc.next().charAt(0); }//do-while while (opt != 'q'); }//main public static void Menu() { System.out.println(" \t 'D' for deposit"); System.out.println(" \t 'W' for withdrawal"); System.out.println(" \t 'q' to stop the program"); } public static int Deposit(int balance, int money) { return balance + money; } public static int Withdrawal(int balance, int money) { return balance - money; } }//class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!