import java.util.*; import java.io.*; class FibApp { private static Scanner keyboardInput = new Scanner (System.in); private static Fib f = new Fib(1); private static final int REC = 1; private static final int NONREC = 2; private static final int ENTER = 3; private static final int EXIT = -1; private static int n=0; // main program public static void main(String[] args) throws Exception { int choice; n = 0; while ((choice = displayMenu()) != -1) { choiceAction(choice); } } // display Menu and get choice private static int displayMenu() { int tmp = 0; try { System.out.println("Computing Fibonacci number..."); System.out.println(REC + " Recursive version"); System.out.println(NONREC + " Non Recursive version"); System.out.println(ENTER + " New Number"); 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 int getInputN() { int tmp = 0; try { System.out.print("Enter the integer: "); tmp = keyboardInput.nextInt(); } catch (Exception e) { keyboardInput.next(); } return(tmp); } private static void choiceAction(int choice) { switch(choice) { case ENTER: n = getInputN(); f = new Fib(n+1); break; case REC: System.out.println("Recursively: F("+n+") = "+f.recFib(n)); break; case NONREC: System.out.println("Non-recursively: F("+n+") = "+f.fib(n)); break; default: System.out.println("Incorrect option!"); break; } } }