Question

In: Computer Science

Class, Let's create a menu in Java. A menu is a presentation of options for you...

Class,
 
    Let's create a menu in Java. A menu is a presentation of options for you to select.

 
You can do this in the main() method.

 
1. Create a String variable named menuChoice. 
 
2. Display 3 options for your program. I recommend using 3 System.out.println statements and a 4th System.out.print to show "Enter your Selection:". This needs to be inside the do -- while loop.
 
       A. Deposit Cash.
 
       B. Withdraw Cash
 
       X. Exit
 
       Enter your Selection:
 
3. Prompt for the value menuChoice.
 
4. If menuChoice is "A", display "Do Deposit" and redisplay the menu.
 
    If menuChoice is "B", display "Do withdrawal" and redisplay the menu.
 
    If menuChoice is "X", the loop needs to terminate.
 
    If any other choice is given, display "Invalid selection" and redisplay the menu.

 
For grading, I will test with uppercase characters. 
 
5 point bonus - Convert the menuChoice to an upper case String after input or as part of the input but before any processing is done. This will allow me to enter 'a' but process as 'A'.
 
5 point bonus - For Task 4 - Create  2 void methods  - 1 for option A to call, and another for option B to call. Do the display work only inside these methods and call these methods for these options. 

Solutions

Expert Solution

Step 1 - Create a file BankMenu.java. Its content will be

import java.util.Scanner;

public class BankMenu {

    private static void doDeposit() {

        System.out.println("Do Deposit");

    }

    private static void doWithdraw() {

        System.out.println("Do withdrawal");

    }

    public static void main(String[] args) {

        char menuChoice;

        Scanner sc = new Scanner(System.in);

        do {

  System.out.println("\n"); // For Output Formatting

            System.out.println("A. Deposit Cash.");

            System.out.println("B. Withdraw Cash");

            System.out.println("X. Exit");

            System.out.print("Enter your Selection: ");

            menuChoice = sc.next().charAt(0); // Taking input from user

            menuChoice = Character.toUpperCase(menuChoice); // Converting input to UpperCase character;

            switch(menuChoice){

                case 'A': doDeposit();

                break;

                case 'B': doWithdraw();

                break;

                case 'X': break;

                default: System.out.println("Invalid Choice");

            }

        } while(menuChoice != 'X');

    }

}

Step 2- Compile this file using command javac BankMenu.java

Step 3 - Run this file using command java BankMenu

I am attaching a screenshot with sample input and output

You can clearly see in the picture

- For input, a and A.It is printing Do Deposit

- For input, b and B.It is printing Do withdrawal

- For input, c. It is printing Invalid Choice

- For input X. The program got exited.

Similarly, you can check for multiple inputs. Please let me know if you want further explanations in the comment section.


Related Solutions

Create a menu in Java. A menu is a presentation of options for you to select....
Create a menu in Java. A menu is a presentation of options for you to select. You can do this in the main() method. 1. Create a String variable named menuChoice. 2. Display 3 options for your program. I recommend using 3 System.out.println statements and a 4th System.out.print to show "Enter your Selection:". This needs to be inside the do -- while loop. A. Buy Stock. B. Sell Stock X. Exit Enter your Selection: 3. Prompt for the value menuChoice....
create a menu in Java. A menu is a presentation of options for you to select....
create a menu in Java. A menu is a presentation of options for you to select. The article above that is in our discussion board may be helpful. You can do this in the main() method. 1. Create a String variable named menuChoice. 2. Display 3 options for your program. I recommend using 3 System.out.println statements and a 4th System.out.print to show "Enter your Selection:". This needs to be inside the do -- while loop. A. Buy Stock. B. Sell...
Create a Java class file for a Car class. In the File menu select New File......
Create a Java class file for a Car class. In the File menu select New File... Under Categories: make sure that Java is selected. Under File Types: make sure that Java Class is selected. Click Next. For Class Name: type Car. For Package: select csci2011.lab7. Click Finish. A text editor window should pop up with the following source code (except with your actual name): csci1011.lab7; /** * * @author Your Name */ public class Car { } Implement the Car...
Create a Java class file for an Account class. In the File menu select New File......
Create a Java class file for an Account class. In the File menu select New File... Under Categories: make sure that Java is selected. Under File Types: make sure that Java Class is selected. Click Next. For Class Name: type Account. For Package: select csci1011.lab8. Click Finish. A text editor window should pop up with the following source code (except with your actual name): csci1011.lab8; /** * * @author Your Name */ public class Account { } Implement the Account...
For Java Let's get some practice with maps! Create a public class CountLetters providing a single...
For Java Let's get some practice with maps! Create a public class CountLetters providing a single static method countLetters. countLetters accepts an array of Strings and returns a Map from Strings to Integers. (You can reject null arguments using assert.) The map should contain counts of the passed Strings based on their first letter. For example, provided the array {"test", "me", "testing"} your Map should be {"t": 2, "m": 1}. You should ignore empty Strings and not include any zero...
Use C++ to create an application that provide the menu with two options TemperatureConverter_Smith.cpp MENU CONVERTER...
Use C++ to create an application that provide the menu with two options TemperatureConverter_Smith.cpp MENU CONVERTER TEMPERATURE – JAMES SMITH Convert Fahrenheit temperature to Celsius Convert Celsius temperature to Fahrenheit Exit CASE 1: Convert Fahrenheit temperature to Celsius -Display the message to ask to enter Fahrenheit degree from the keyboard -Use the following formula to convert to Celsius degree         Celsius Temperature = (Fahrenheit Temperature – 32) * 5/9 ; -Display the output as below: TemperatureConverter_Smith.cpp TEMPERATURE CONVERTER – JAMES...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main()...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main() function to coordinate the execution of the program. We will need methods: Method for Depositing values into the account. What type of method will it be? Method for Withdrawing values from the account. What type of method will it be? Method to output the balance of the account. What type of method will it be? Method that will output all deposits made to the...
in java Write a Java Program that displays a menu with five different options: 1. Lab...
in java Write a Java Program that displays a menu with five different options: 1. Lab Test Average Calculator 2. Dice Roll 3. Circle Area Calculator 4. Compute Distance 5. Quit The program will display a menu with each of the options above, and then ask the user to enter their choice. There is also a fifth option to quit, in which case, the program will simply display a goodbye message. Based on the user’s choice, one of the options...
Use a switch statement to create a menu with the following options Create a Camping Trip...
Use a switch statement to create a menu with the following options Create a Camping Trip Assign a Camper to a Trip Create a Needed Food item Assign a Camper to a Food item For now just print a message prompting user for input and allowing them to return the menu. No functionality is required at this time, but save this code for later use.
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT