Question

In: Computer Science

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.

4. If menuChoice is "A", display "Buy Stock" and redisplay the menu. If menuChoice is "B", display "Sell Stock" 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.

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'. You can Google for "Java string uppercase" to see how this is done.

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

Program code:

import java.util.Scanner;                     //Importing Scanner class

public class menuChoice
{
public static void main(String [] args)
{
String menuChoice;                           //Creating string variable to store user's choice
boolean i=true;                                  //Creating boolean variable for loop iteration
Scanner read=new Scanner(System.in);        //Creating scanner variable to read user's choice
while(i)                     //loop for displaying menu until user want to exit.
{
     System.out.println("\nMenu...");                      //Displaying menu
     System.out.println("A.Buy Stock");
     System.out.println("B.Sell Stock");
     System.out.println("X.Exit");
     System.out.print("\nEnter your choice : ");
     menuChoice=read.next();                                   //Reading user value
     if(menuChoice.equals("a")|| menuChoice.equals("A"))            //Checking whether he entered 'A' or 'a'
     {
          menuChoice=menuChoice.toUpperCase();             //Converting input into upper case.
          choiceA();                                                                //Calling method to display option A value
      }
   else if(menuChoice.equals("b")|| menuChoice.equals("B"))
     {
          menuChoice=menuChoice.toUpperCase();             //Converting input into upper case.
          choiceB();                                                               //Calling method to display option B value
      }
    else if(menuChoice.equals("x")|| menuChoice.equals("X"))
     {
          i=false;                                                                     //Making i=false to exit from the loop
          menuChoice=menuChoice.toUpperCase();             //Converting input into upper case.
      }
    else                  
       System.out.println("Invalid selection.....Please select one from the above.");
}
}

static void choiceA()                         //Method to print BUY STOCK
{
System.out.println("BUY STOCK");
}

static void choiceB()                         //Method to print SELL STOCK
{
System.out.println("SELL STOCK");
}

}

   
Output:


Related Solutions

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...
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...
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 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...
Select an occupation in which you engage and are passionate about. Create a presentation to explain...
Select an occupation in which you engage and are passionate about. Create a presentation to explain how you might teach this occupation. The presentation must include: An introduction (i.e. why chose the occupation, identify area of occupation according to Occupational Therapy Practice Framework); Demonstration/teaching of occupation, Discussion ways to adapt activity and/or context based upon one client that you have observed in the clinic.
Java Create a method to display a menu. When this method is called it should receive...
Java Create a method to display a menu. When this method is called it should receive the user's name, great the user, and ask them to make a selection. 1 - Change your name, 2 - Test your IQ, 3 - Display a table, 4 - Play a game, 5 - Exit.
The application uses Java Object-Oriented features for its implementation. Students select from a menu of courses...
The application uses Java Object-Oriented features for its implementation. Students select from a menu of courses for which they wish to register. The program then validates the user selection against the registration business rules. If the selection is valid, the program prints out a confirmation message. Otherwise, the program prints out the current list of registered classes along with total registered credit hours. The program terminates when the user does not want to register for classes any more. There are...
For this task you will write a persuasive letter, create a PowerPoint presentation, or create a...
For this task you will write a persuasive letter, create a PowerPoint presentation, or create a video presentation to respond to a scenario. Scenario You just got hired as an economic advisor to the President of the United States. You have a difficult task ahead of you. Currently the country is stuck in a crippling recession. The unemployment rate has risen to 8%, and your predecessor made the unwise decision of printing more money to solve the problem. Now, along...
JAVA PROGRAMMING Hi! I need to create a calculator using do/while loop that calls a menu...
JAVA PROGRAMMING Hi! I need to create a calculator using do/while loop that calls a menu switch where the user choice the calculation type. In the switch each case calls a method to each type of calculation (addition/subtraction/division/multiply/ change set of numbers in the array) those methods sends back the result to be displayed in another method. This application needs to hold the user input's numbers as an array. Thanks for your time. It is a great help!
JAVA CODE_ Use menu based functionality and validation loops to create a new customer bonus fruit...
JAVA CODE_ Use menu based functionality and validation loops to create a new customer bonus fruit package application for the Dirt to Dish discount produce company. The program you create will prompt the user to enter a number to select one of three bonus pack options: 1 for Apple pack 2 for Orange pack 3 for Banana pack **Use input validation to ensure a valid option has been selected before proceeding. Use variables to keep track of how many of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT