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 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...
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...
(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...
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...
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...
JAVA FRACTIONS QUESTION: You will create a Fraction class in Java to represent fractions and to...
JAVA FRACTIONS QUESTION: You will create a Fraction class in Java to represent fractions and to do fraction arithmetic. To get you used to the idea of unit testing, this homework does not require a main method. You can create one if you find it useful, however, we will not be grading or even looking at that code. You should be comfortable enough with the accuracy of your test cases that you do not need to use print statements or...
Java Coding Background You will create a Java class that simulates a water holding tank. The...
Java Coding Background You will create a Java class that simulates a water holding tank. The holding tank can hold volumes of water (measured in gallons) that range from 0 (empty) up to a maximum. If more than the maximum capacity is added to the holding tank, an overflow valve causes the excess to be dumped into the sewer system. Assignment The class will be named HoldingTank. The class attributes will consist of two int fields – current and maxCapacity....
In java: -Create a class named Animal
In java: -Create a class named Animal
Create a PowerPoint presentation that you will present to the class -on TWO different body systems....
Create a PowerPoint presentation that you will present to the class -on TWO different body systems. Presentation should be 3-5 minutes in length; 6-8 slides in total. Please refer to the information provided for Assessment 1 for your content. The PowerPoint must include for each body system-  Location  Structure  Function  Information on the interrelationships between major components of the two body systems and other structures  Use correct health terminology and diagrams
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT