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...
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: 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 allow the user to enter a start value from 1 to...
create a program that will allow the user to enter a start value from 1 to 5, a stop value from 10 to 12 and a multiplier from 1 to 4. the program must display a multiplication table from the values entered. for example if the user enters: start 2, stop 10 and multiplier 3, the table should appear as follows: 3*2=6 3*3=9 3*4=12 . . . 3*10=30
create a Visual Basic project with the following features: 1. The user interface can display the...
create a Visual Basic project with the following features: 1. The user interface can display the following information, one textbox for one item: 1a. Author, in the form of Lastname, Firstname 1b. Title 1c. Source -- where the paper is published 1d. Abstract 1e. Publication year (This information is in the 1c. Source, but display the publication year separately here) 2. There is a command button "Import". It would allow the user to select the eric.txt as the input file...
Using If-Else conditional statement write a Visual Basic Program to display: (i) “STOP” if the user...
Using If-Else conditional statement write a Visual Basic Program to display: (i) “STOP” if the user enters “R” (ii) “CAUTION” if the user enters “Y” (iii) “GO” if the user enters “G” (iv) “Invalid” if the user enters any other character
create a program that asks user math questions and keeps track of answers... Python Allow the...
create a program that asks user math questions and keeps track of answers... Python Allow the user to decide whether or not to keep playing after each math challenge. Ensure the user’s answer to each math problem is greater than or equal to zero. Keep track of how many math problems have been asked and how many have been answered correctly. When finished, inform the user how they did by displaying the total number of math problems, the number they...
Description: To create a Visual Basic program that will obtain a sentence from the user, parse...
Description: To create a Visual Basic program that will obtain a sentence from the user, parse the sentence, and then display a sorted list of the words in the sentence with duplicate words removed. Tasks: Design a method (algorithm) to solve the above problem using pseudocode or a flowchart. Translate your algorithm into an appropriate VB program and test it using the following input sentence. "We are the world We are the children" Submit: Pseudocode version of algorithm/Flowchart version of...
Program on Visual Basic, VBA Create an application that lets the user enter a number of...
Program on Visual Basic, VBA Create an application that lets the user enter a number of seconds and produces output according to the following criteria: There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT