/* Name: p1.java Description: This program will demonstrate some simple JAVA programming techniques. */ public class p1 { public static void main(String[] args) { final int ACTION_1 = 1; final int ACTION_2 = 2; final int ACTION_3 = 3; final int ACTION_EXIT = 9; int action = 9; ConsoleReader console = new ConsoleReader(System.in); while(true) { System.out.println("\nWelcome to CS40 Programming Example\n"); System.out.println(ACTION_1 + ") Print your name in HEX"); System.out.println(ACTION_2 + ") Simple number calculations"); System.out.println(ACTION_3 + ") Your Turn !!!"); System.out.println(ACTION_EXIT + ") Exit\n"); System.out.print("Enter choice ==> "); action = console.readInt(); switch(action) { case ACTION_1: { int i; String name; System.out.println("\nPlease enter your name"); System.out.print("==> "); name = console.readLine(); for (i = 0; i < name.length(); i++) { System.out.printf("%c ", name.charAt(i)); } System.out.printf("\n"); for (i = 0; i < name.length(); i++) { System.out.printf("%x ", name.codePointAt(i)); } System.out.printf("\n"); break; } case ACTION_2: { double n1, n2; System.out.println("\nEnter first number"); System.out.print("==> "); n1 = console.readDouble(); System.out.println("Enter second number"); System.out.print("==> "); n2 = console.readDouble(); System.out.printf("\nAdd = %f\n", n1 + n2); System.out.printf("Sub = %f\n", n1 - n2); System.out.printf("Mul = %f\n", n1 * n2); System.out.printf("Div = %f\n", n1 / n2); break; } case ACTION_3: { break; } case ACTION_EXIT: { System.out.println("\n Good bye\n"); return; } } } } }