I am writing this program (in Java). The program takes input from user and accumulates and ending balance by making depostis or withdrawals.  Inside of differentOptions method when the user enters option W for withdrawal, my code is nor working properly. If the amount entered is less than the ending balance the user should not be alow to do the withdrawal and there is supposed to be a deduction of $20 from the ending balance. However my code is allowing the user to do the withdrawal even when the balance is 0. In addition, in the same loop, I want to display a message that says "please try again " in case user enters for example a letter, but I am getting an error message. I copied and pasted my code here and also attached pictures.        import java.util.*; public class AccountTransactionProject {   public static void main(String[] args) { Scanner console= new Scanner(System.in);   welcomeMenu(); differentOperations();     } public static void displayMenu() { // method that prints all the options of the main menu to the user 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() { // method that takes the first character of the option entered //from the displayMenu method and converts it to upper case Scanner console= new Scanner(System.in); String temp= console.next().toUpperCase(); return temp.charAt(0);     } public static void welcomeMenu() { //method that welcomes the user and ask if they want to //continue using the program or exit it Scanner console= new Scanner(System.in); System.out.println("Hello! This program is going to help you to keep track " + "of your account balance.\nYou will be able to make deposits, " + "withdrawals and see you 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() { /* method that takes answer from welcomeMethod and starts * taking data from user to do operations or quit the program * when requested by user  * */ 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) {                         balance += amount;                     }                     else {                         System.out.println("Invalid input, try again.");                         }                 }                 else if(choiceEntered== 'W') {                     System.out.println("Make a withdrawal");                     System.out.println("Enter amount for withdrawal: ");                    double withDrawalAmount= console.nextDouble();                    if(withDrawalAmount >= endingBalance) {                    endingBalance -= withDrawalAmount;                    System.out.println("Withdrawal approved. You are all set!");                    }else if(withDrawalAmount < endingBalance) {                   System.out.println("Insuficient funds. Your withdrawal has been cancelled.");                   System.out.println("A $20 fee will be deducted from your balance.");                   endingBalance -= 20;                    }else {                    System.out.println("Invalid input. Please try again!");                    }                 }                 else {                     System.out.println("Invalid input. Please try again!");                 }                 displayMenu();                 choiceEntered= getInput();             }             System.out.println("You are exiting this program. See you later!");         } } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I am writing this program (in Java). The program takes input from user and accumulates and ending balance by making depostis or withdrawals. 

Inside of differentOptions method when the user enters option W for withdrawal, my code is nor working properly. If the amount entered is less than the ending balance the user should not be alow to do the withdrawal and there is supposed to be a deduction of $20 from the ending balance. However my code is allowing the user to do the withdrawal even when the balance is 0. In addition, in the same loop, I want to display a message that says "please try again " in case user enters for example a letter, but I am getting an error message.

I copied and pasted my code here and also attached pictures. 

 

 

 

import java.util.*;

public class AccountTransactionProject {

 

public static void main(String[] args) {

Scanner console= new Scanner(System.in);

 

welcomeMenu();

differentOperations();

    }

public static void displayMenu() {

// method that prints all the options of the main menu to the user

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() {

// method that takes the first character of the option entered

//from the displayMenu method and converts it to upper case

Scanner console= new Scanner(System.in);

String temp= console.next().toUpperCase();

return temp.charAt(0);

    }

public static void welcomeMenu() {

//method that welcomes the user and ask if they want to

//continue using the program or exit it

Scanner console= new Scanner(System.in);

System.out.println("Hello! This program is going to help you to keep track "

+ "of your account balance.\nYou will be able to make deposits, "

+ "withdrawals and see you 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() {

/* method that takes answer from welcomeMethod and starts

* taking data from user to do operations or quit the program

* when requested by user 

* */

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) {

                        balance += amount;

                    }

                    else {

                        System.out.println("Invalid input, try again.");

                        }

                }

                else if(choiceEntered== 'W') {

                    System.out.println("Make a withdrawal");

                    System.out.println("Enter amount for withdrawal: ");

                   double withDrawalAmount= console.nextDouble();

                   if(withDrawalAmount >= endingBalance) {

                   endingBalance -= withDrawalAmount;

                   System.out.println("Withdrawal approved. You are all set!");

                   }else if(withDrawalAmount < endingBalance) {

                  System.out.println("Insuficient funds. Your withdrawal has been cancelled.");

                  System.out.println("A $20 fee will be deducted from your balance.");

                  endingBalance -= 20;

                   }else {

                   System.out.println("Invalid input. Please try again!");

                   }

                }

                else {

                    System.out.println("Invalid input. Please try again!");

                }

                displayMenu();

                choiceEntered= getInput();

            }

            System.out.println("You are exiting this program. See you later!");

        }

}

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Hiring Problem
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education