Main.java (810B)
1 import java.util.Scanner; 2 3 public class Main { 4 private static String msgs[] = { 5 "set the Time", 6 "set the Alarm time", 7 "quit" 8 }; 9 private static String keys[] = { 10 "S", 11 "A", 12 "q" 13 }; 14 15 private static void printMenu() { 16 System.out.println("What do you want to do?"); 17 for (int i = 0; i < msgs.length; i++) 18 System.out.println(keys[i] + " - " + msgs[i]); 19 } 20 21 private static void runMenu() { 22 Scanner sc = new Scanner(System.in); 23 while (true) { 24 printMenu(); 25 String in = sc.nextLine(); 26 27 28 switch (in.charAt(0)) { 29 case 'q': return; 30 case 'S': System.out.println("Set time"); break; 31 case 'A': System.out.println("Set alarm time"); break; 32 default: System.out.println("Invalid menu item " + in); break; 33 } 34 } 35 } 36 37 public static void main(String[] args) { 38 runMenu(); 39 } 40 }