this is in java create a method called MenuPrintAndSelect that is sent no date b
ID: 3651566 • Letter: T
Question
this is in javacreate a method called MenuPrintAndSelect that is sent no date but returns an integer thar represents a selected menu item 1-4. when this method is called it will print the following menu and request the user to select an option. the function will then send that selection back to the calling procedure:
1.) magic 8-ball
2.) pig latin
3.) random card
4.) exit
**for option 1 create a method that will accept a string argument(call it the question) and will return a message (the answer) the rules of this method are simple. follow the chart below to determine what answer the function should return:
length of question | length is even | length is odd
1-10 " | Yes, in due time." | "My sources say no."
11-20 | "Definitely not." | "Yes!"
21-25 | "You will have to wait.." | "I have my doubts."
26-30 | "Outlook so so." " | "Looks good to me!"
>30 | "NO!" | "ARE YOU KIDDING?"
** for option 2 (pig latin) create a method that will accept a single string argument(single word) and return the pig latin version of that word. the rules are simple for this as well but you are not required to implement the full set of them in this question. the rules you will need to implement are the following:
1.) words that dont start with vowels: take the first letter of the word and place it at the end and add "ay"
ex) latin -> atinlay
2.) words that start with vowels
: simply add "hay" to the end of the word and leave the first letter in front.
ex) egg-> egghay
note: lower case the return word. allow the user to enter a single word(no spaces) and display to them the converted word. an error should display if they have a space.
** for option 3(random card) create a function that will send back a random card from a normal deck of cards.
Explanation / Answer
class Main { public void display_menu() { System.out.println ( "1.) magic 8-ball 2.) pig latin 3.) random card 4.) exit " ); System.out.print ( "Selection: " ); } public Main() { Scanner in = new Scanner ( System.in ); display_menu(); switch ( in.nextInt() ) { case 1: System.out.println ( "You picked option 1" ); break; case 2: System.out.println ( "You picked option 2" ); break; case 3: System.out.println ( "You picked option 3" ); break; default: System.err.println ( "Unrecognized option" ); break; } } public static void main ( String[] args ) { new Main(); }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.