Question

In: Computer Science

We need to create basic program that will simply display a menu and allow the user...

We need to create basic program that will simply display a menu and allow the user to select one of the choices. The menu should be displayed such that each option will be numbered, as well as have one capital letter so as to indicate that either the number or the designated letter can be entered to make their choice. Once the choice is made, the sub-menu for that selection should be displayed. Colors with an odd number of letters should display the following choices in this order: 1, 2, 6, 5. Words with an even number of letters should display the following choices in this order: 7, 8, 4, 3. Once this choice is made the appropriate “fortune”is displayed.

program Requirements: 1.You MUST use methods for this assignment. You are required to have the following methods, but you can add more if you desire.

a.private static String userSelection(Scanner input)

b.private static void displayColorMenu()

c.private static void displayEvenMenu()

d.private static void display OddMenu()

e.private static void displayFortune(String number)

2.Your output needs to match the example formatting exactly, as well as the fortunes listed below! Note: you will lose points for spelling, capitalization, etc. errors! There is a space after the colons and a return carriage after the “fortune line.

1.You will soon take a trip

2.You will have good luck today

3.You will go to a party soon

4.Wealth awaits you very soon

5.You will have many friends

6.Serious trouble will pass you by

7.You will get an 'A' on the future

8.You will get free food today

Sample Execution:

Please choose your color:

1. Red

2. Green

3. Blue

4. Yellow

1

Please choose your number:

1

2

6

5

1

You will soon take a trip

Solutions

Expert Solution

Program:

import java.io.*;       //import packages
import java.util.*;
public class Fortune   // class Fortune
{  
   private static String userSelection(String n)   // call userSelection function
   {
       String ss="";       // initializing the string
       if(n.equals("1"))       // checking condition with 1
       ss="You will soon take a trip";       //assign value
       else if(n.equals("2"))   // checking condition with 2
       ss="You will have good luck today";       //assign value
       else if(n.equals("3"))   // checking condition with 3
       ss="You will go to a party soon";       //assign value
       else if(n.equals("4"))   // checking condition with 4
       ss="Wealth awaits you very soon";       //assign value
       else if(n.equals("5"))   // checking condition with 5
       ss="You will have many friends";       //assign value
       else if(n.equals("6"))   // checking condition with 6
       ss="Serious trouble will pass you by";       //assign value
       else if(n.equals("7"))   // checking condition with 7
       ss="You will get an 'A' on the future";       //assign value
       else if(n.equals("8"))   // checking condition with 8
       ss="You will get free food today";           //assign value  
       return ss;       // return result
   }       // end function
  
   private static void displayColorMenu()   // function displayColorMenu
   {
       System.out.println("1. Red\n2. Green\n3. Blue\n4. Yellow");       // display colors
       Scanner sc=new Scanner(System.in);       // scanner object
       int n1;
       System.out.println("Please choose your color:");   // display message
       n1=sc.nextInt();       // read value from user
       if(n1==1 || n1==2)       // check condition
       displayOddMenu();       // call displayOddMenu function
       else if(n1==3 || n1==4)   // check condition
       displayEvenMenu();       // call displayEvenMenu function
   }       // end function  
  
   private static void displayEvenMenu()   // function displayEvenMenu
   {
       System.out.println("Please choose your number:");   // display message
       System.out.println("7\n8\n4\n3");           // display values
       Scanner sc=new Scanner(System.in);           // create scanner object
       String n1;      
       n1=sc.next();                   // read value from user
       displayFortune(n1);               // call displayFortune function
   }           // end function
  
   private static void displayOddMenu()   // function displayOddMenu
   {  
       System.out.println("Please choose your number:");   // display message
       System.out.println("1\n2\n6\n5");               //display message      
       Scanner sc=new Scanner(System.in);       // scanner object
       String n1;      
       n1=sc.next();           // read value from user
       displayFortune(n1);       // call displayFortune function
   }           // end function
  
   private static void displayFortune(String number)   // function displayFortune
   {
       System.out.println(userSelection(number));       // call userSelection function
   }       // end function
      
   public static void main(String[] args)    // main function
   {
           displayColorMenu();               // call displayColorMenu
   }       // end main function
}

Program Screenshots:

OUTPUT SCREEN SHOT:


Related Solutions

Create a menu-based program that will allow the user to calculate the area for a few...
Create a menu-based program that will allow the user to calculate the area for a few different shapes: square, rectangle, parallelogram, and circle. Refer to the Sample Output in this document to see what menu options you should use. Create PI as a global constant variable. Main Function use do-while to repeat program until user chooses option 5 call the displayMenu function get user choice & validate with while loop depending on user’s choice, get the data required to calculate...
Create a menu-based program that will allow the user to calculate the area for a few...
Create a menu-based program that will allow the user to calculate the area for a few different shapes: square, rectangle, parallelogram, and circle. Refer to the Sample Output in this document to see what menu options you should use. Create PI as a global constant variable. Main Function use do-while to repeat program until user chooses option 5 call the displayMenu function get user choice & validate with while loop depending on user’s choice, get the data required to calculate...
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user...
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user to choose options. The program must have a file dialogue box for text file. Output should be based on user choices. Read in a file Print the file to the console Encrypt the file and write it to the console Write out the encrypted file to a text file Clear the data in memory Read in an encrypted file Decrypt the file Write out...
Write a program to prompt the user to display the following menu: Sort             Matrix                   Q
Write a program to prompt the user to display the following menu: Sort             Matrix                   Quit If the user selects ‘S’ or ‘s’, then prompt the user to ask how many numbers you wish to read. Then based on that fill out the elements of one dimensional array with integer numbers. Then sort the numbers and print the original and sorted numbers in ascending order side by side. How many numbers: 6 Original numbers:                     Sorted numbers 34                                                                         2          55                                                      ...
Write a program to prompt the user to display the following menu: Sort             Matrix                   Q
Write a program to prompt the user to display the following menu: Sort             Matrix                   Quit If the user selects ‘S’ or ‘s’, then prompt the user to ask how many numbers you wish to read. Then based on that fill out the elements of one dimensional array with integer numbers. Then sort the numbers and print the original and sorted numbers in ascending order side by side. How many numbers: 6 Original numbers:                     Sorted numbers 34                                                                         2          55                                                      ...
PYTHON In this lab we will design a menu-based program. The program will allow users to...
PYTHON In this lab we will design a menu-based program. The program will allow users to decide if they want to convert a binary number to base 10 (decimal) or convert a decimal number to base 2 (binary). It should have four functions menu(), reverse(), base2(), and base10(). Each will be outlined in detail below. A rubric will be included at the bottom of this document. Menu() The goal of menu() is to be the function that orchestrates the flow...
Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names     &
Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close Do you...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                       ...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close...
Create a program that will ask the user to choose their order from a simple menu....
Create a program that will ask the user to choose their order from a simple menu. Customers first choose from three types of dishes: Sandwiches/wraps, Rice Meals, or Noodles. They can type in 1, 2, or 3 to select the type then, they choose a specific dish as shown below. Confirm their order by displaying it on the screen after they make their selection. 1. Sandwiches/wraps Hamburger Chicken shawarma 2. Rice meals Arroz con pollo Chana masala 3. Noodles Chow...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Important! Consider which control structures will work best for which aspect of the assignment. For example, which would be the best to use for a menu?...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT