Advertisement
fromMars

Java CLI InputMenu by Mars

Apr 21st, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class InputMenu
  4. {
  5.   public void display_menu()
  6.   {
  7.     System.out.println("1) Option 1\n2) Option 2\n3) Option 3");
  8.     System.out.print("Selection: ");
  9.   }
  10.  
  11.   public void question()
  12.   {
  13.     System.out.println("Would you like to proceed or quit?");
  14.     System.out.println("To proceed enter 9.");
  15.     System.out.println("If you wish to quit enter 0.");
  16.  
  17.     Scanner q = new Scanner(System.in);
  18.  
  19.     switch (q.nextInt())
  20.     {
  21.       case 0:
  22.       System.out.println("Thank you and goodbye");
  23.       break;
  24.  
  25.       case 9:
  26.       System.out.println("Please proceed.");
  27.       new InputMenu();
  28.       break;
  29.  
  30.       default:
  31.       System.err.println("Unrecognized option");
  32.       break;
  33.     }
  34.   }
  35.  
  36.   public InputMenu()
  37.   {
  38.     Scanner in = new Scanner(System.in);
  39.        display_menu();
  40.  
  41.       switch (in.nextInt())
  42.       {
  43.         case 1:
  44.         System.out.println("You picked option 1");
  45.         question();
  46.         break;
  47.  
  48.         case 2:
  49.         System.out.println("You picked option 2");
  50.         question();
  51.         break;
  52.  
  53.         case 3:
  54.         System.out.println("You picked option 3");
  55.         question();
  56.         break;
  57.  
  58.         default:
  59.         System.err.println("Unrecognized Option");
  60.         break;
  61.       }
  62.   }
  63.  
  64.   public static void main(String[] args) {
  65.     new InputMenu();
  66.   }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement