Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

printMenu() and main() Add a method to your Loops class called printMenu() that

ID: 3638333 • Letter: P

Question

printMenu() and main()
Add a method to your Loops class called printMenu() that prints a menu with one option for each method in this class, plus an option to quit. The printMenu() method should prompt the user to make a selection and return the number of the option that the user chose. Add a “main” method, that repeatedly prints the menu, and then calls the method corresponding to the option that the user chose until the user opts to quit. Add code to your main method to collect user input for the factorial method, and then pass the user input as a parameter when you call the method.

Explanation / Answer

I think this may help you, it is in C#: -------------- namespace printMenu { class Program { static void Main(string[] args) { printer pr = new printer(); bool cond = true; while (cond) { Console.WriteLine("please type a character"); Console.WriteLine("a - menu of 1s"); Console.WriteLine("b - menu of 2s"); Console.WriteLine("c - menu of 3s"); Console.WriteLine("q - to quit"); cond = pr.printMenu(Console.ReadLine()); } } } class printer { public int[] a = { 1, 1, 1 }, b = { 2, 2, 2 }, c = { 3, 3, 3 }; public bool printMenu(string choice) { bool check = true; switch (choice) { case ("a"): foreach (int item in a) { Console.WriteLine(item); } break; case ("b"): foreach (int item in b) { Console.WriteLine(item); } break; case ("c"): foreach (int item in c) { Console.WriteLine(item); } break; case ("q"): Console.WriteLine("End"); check = false; break; default: break; } return check; } } }