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...
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.
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...
Write a menu program to have the above options for the polynomials. Your menu program should...
Write a menu program to have the above options for the polynomials. Your menu program should not use global data; data should be allowed to be read in and stored dynamically. Test your output with the data below. Poly #1: {{2, 1/1}, {1, 3/4}, {0, 5/12}} Poly #2: {{4, 1/1}, {2, -3/7}, {1, 4/9}, {0, 2/11}} provide a C code (only C please) that gives the output below: ************************************ *         Menu HW #4 * * POLYNOMIAL OPERATIONS * * 1....
Select one of the options below and create a linear equation to represent the monthly bill...
Select one of the options below and create a linear equation to represent the monthly bill for each Plan A and Plan B, you will have two equations, one for each plan. Find the common number of minutes at which both Plan A and Plan B cost the same amount. This number of minutes is called the break-even point. Which plan costs more before the break-even point and which cost more after the break-even point. Option 1: Plan A $39.99...
Create a 15 slide PowerPoint presentation of the pediatric condition you selected. Ensure that your presentation...
Create a 15 slide PowerPoint presentation of the pediatric condition you selected. Ensure that your presentation addresses: Developmental dysplasia of the hip Description and etiology  of the condition Epidemiology for the condition Pathophysiology Clinical Manifestation Diagnostic evaluation Therapeutic Management: Be sure to address medication as well as surgical and non-surgical management if applicable Care Management to include nursing intervention The presentation should have a title slide and a reference slide. They are not included in the slide count.
Create a 15 slide PowerPoint presentation of the pediatric condition you selected. Ensure that your presentation...
Create a 15 slide PowerPoint presentation of the pediatric condition you selected. Ensure that your presentation addresses: Description and etiology  of the condition Epidemiology for the condition Pathophysiology Clinical Manifestation Diagnostic evaluation Therapeutic Management: Be sure to address medication as well as surgical and non-surgical management if applicable Care Management to include nursing intervention The presentation should have a title slide and a reference slide. They are not included in the slide count. Choose a Pediatric Condition and Create a 15...
Explain what economists mean by “menu costs.” (select all that apply) A. Menu costs are the...
Explain what economists mean by “menu costs.” (select all that apply) A. Menu costs are the costs to seller of changing their product line B. Menu costs are the costs to seller of rapidly changing their prices. C. Menu costs are the costs to the employer of buying dinner for the company party D. Menu costs are the profit benefits to suppliers of rapidly changing their prices.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT