import java.util.*; import java.io.*; class MSortApp { private static Scanner keyboardInput = new Scanner (System.in); private static MSort s = new MSort(); private static final int INPUT = 0; private static final int PRINTALL = 1; private static final int MSORT = 2; private static final int EXIT = -1; // main program public static void main(String[] args) throws Exception { int choice; s.input(); while ((choice = displayMenu()) != -1) { choiceAction(choice); } } // display Menu and get choice private static int displayMenu() { int tmp = 0; try { System.out.println(); System.out.println(" " + INPUT + " Input numbers again"); System.out.println(" " + PRINTALL + " Print all numbers"); System.out.println(" " + MSORT + " Merge sort ascendingly"); System.out.println(" " + EXIT + " Exit"); System.out.print(" Choose one of the above options: "); tmp = keyboardInput.nextInt(); } catch (Exception e) { keyboardInput.next(); } return(tmp); } private static void choiceAction(int choice) { switch(choice) { case INPUT: s.input(); break; case MSORT: s.msort(); break; case PRINTALL: s.printAll(); break; default: System.out.println("Incorrect option!"); break; } } }