/* Menu3.java CIS 160 David Klick 2004-09-20 Demonstrates post-test loop implementing a menu */ import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class Menu3 { public static void main(String[] args) throws IOException { BufferedReader kbd = new BufferedReader( new InputStreamReader(System.in)); String strIn; char choice; do { // This next instruction clears some space on the screen System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); System.out.println("Main menu\n"); System.out.println(" 1. (E)ncouragement\n"); System.out.println(" 2. (A)dvice\n"); System.out.println(" 3. The (t)ruth\n"); System.out.println(" 4. (Q)uit\n"); System.out.print("Please enter choice: "); strIn = kbd.readLine(); choice = strIn.toUpperCase().charAt(0); System.out.println(); switch (choice) { case '1': case 'E': System.out.println("Things could get worse."); break; case '2': case 'A': System.out.println("Don't eat anything bigger than your head."); break; case '3': case 'T': System.out.println("You can't handle the truth."); break; case '4': case 'Q': // no need to do anything since we are quitting break; default: System.out.println("Invalid choice, moron!"); } if (choice != '4' && choice != 'Q') { System.out.print("\nPress enter to continue "); strIn = kbd.readLine(); } } while (choice != '4' && choice != 'Q'); System.out.println("\nHave a nice day."); } }