I am writing this program that gives the user options. When I choose "make a deposit" and "then see balance" the amount entered is not accumulating and printing as Ending balance. How can I do that? how can I acculmualte all the money entered ? a lot of times and them print whenever I ask for? I copied it here and attached pictures import java.util.*; public class AccountTransactionAssignment { public static void main(String[] args) { Scanner console= new Scanner(System.in); welcomeMenu(); differentOperations(); } public static void displayMenu() { System.out.println(); System.out.println("Enter your choice: "); System.out.println("\tB See Balance"); System.out.println("\tD Make Deposit"); System.out.println("\tW Make a Withdrawal"); System.out.println("\tQ Quit "); } public static char getInput() { Scanner console= new Scanner(System.in); String temp= console.next().toUpperCase(); returntemp.charAt(0); } public static void welcomeMenu() { Scanner console= new Scanner(System.in); System.out.println("Hello! This program is going to help you to keep track " + "of your account balance.\n"); System.out.println("Would you like to continue? Enter yes.\nNo help needed " + "at this time? Enter no.\n"); } public static void differentOperations() { Scanner console= new Scanner(System.in); String option= console.next(); if(option.equalsIgnoreCase("no")){ System.out.println("You are exiting this program, see you later!"); } else { System.out.println("Lets get started!"); displayMenu(); char choiceEntered= getInput(); double endingBalance= 0; double balance= 0; double amount= 0; while(choiceEntered != 'Q') { endingBalance= balance; if(choiceEntered == 'B') { System.out.println("Your ending balance is: "+balance); } else if(choiceEntered == 'D') { System.out.println("Make a deposit"); System.out.println("How much do you want to deposit? "); amount= console.nextDouble(); if(amount > 0) { endingBalance += amount; } else { System.out.println("Invalid input, try again."); } } else if(choiceEntered== 'W') { System.out.println("Make a withdrawal"); } else { System.out.println("Invalid input. Please try again!"); } displayMenu(); choiceEntered= getInput(); } System.out.println("You are exiting this program. See you later!"); } } }
I am writing this
I copied it here and attached pictures
import java.util.*;
public class AccountTransactionAssignment {
public static void main(String[] args) {
Scanner console= new Scanner(System.in);
welcomeMenu();
differentOperations();
}
public static void displayMenu() {
System.out.println();
System.out.println("Enter your choice: ");
System.out.println("\tB See Balance");
System.out.println("\tD Make Deposit");
System.out.println("\tW Make a Withdrawal");
System.out.println("\tQ Quit ");
}
public static char getInput() {
Scanner console= new Scanner(System.in);
String temp= console.next().toUpperCase();
returntemp.charAt(0);
}
public static void welcomeMenu() {
Scanner console= new Scanner(System.in);
System.out.println("Hello! This program is going to help you to keep track "
+ "of your account balance.\n");
System.out.println("Would you like to continue? Enter yes.\nNo help needed "
+ "at this time? Enter no.\n");
}
public static void differentOperations() {
Scanner console= new Scanner(System.in);
String option= console.next();
if(option.equalsIgnoreCase("no")){
System.out.println("You are exiting this program, see you later!");
}
else {
System.out.println("Lets get started!");
displayMenu();
char choiceEntered= getInput();
double endingBalance= 0;
double balance= 0;
double amount= 0;
while(choiceEntered != 'Q') {
endingBalance= balance;
if(choiceEntered == 'B') {
System.out.println("Your ending balance is: "+balance);
}
else if(choiceEntered == 'D') {
System.out.println("Make a deposit");
System.out.println("How much do you want to deposit? ");
amount= console.nextDouble();
if(amount > 0) {
endingBalance += amount;
}
else {
System.out.println("Invalid input, try again.");
}
}
else if(choiceEntered== 'W') {
System.out.println("Make a withdrawal");
}
else {
System.out.println("Invalid input. Please try again!");
}
displayMenu();
choiceEntered= getInput();
}
System.out.println("You are exiting this program. See you later!");
}
}
}
Step by step
Solved in 6 steps with 2 images