import java.io.*; /** Lab 12. CS1110 Exception handling */ public class ExceptionHandling { /** Yields: a buffered reader attached to the keyboard. If you store * this value in a variable such as kbd, then * * kbd.readLine() * * will prompt the reader to type a line by putting in the interactions * pane a field into which to type and will then yield the string of * characters the user typed in. */ public static BufferedReader getKeyboard() { // Create and store in kbd a link to the keyboard return new BufferedReader(new InputStreamReader(System.in)); } /** Prompt the reader to type a line into the interactions pane and * return the line that the user types (e.g. this is function with * side-effects). * Yields: The text the user typed into the interactions pane * Throws: IOException if there is a hardware issue */ public static String readKeyboardLine() throws IOException { BufferedReader kyboard= getKeyboard(); String line = kyboard.readLine(); return line; } /** Prompt the reader to type an integer (an int) into the interactions pane * and return the integer that they type. If the user types something that * is not an int, then issue a message (System.out.println(...) and prompt * again (HINT: Use recursion). * Yields: the number the user typed into the interactions pane * Throws: IOException if there is a hardware issue or if the user * did not type a number. */ public static int readKeyboardInt() throws IOException { BufferedReader kyboard= getKeyboard(); /** INSERT YOUR CODE HERE */ return 0; // Stub return } /** Yields: b**c. * Precondition: c � 0 */ public static double exp(double b, int c) { if (c == 0) { return 1; } // c > 0 if (c % 2 == 0) { return exp(b*b, c / 2); } // c is odd and > 0 return b * exp(b, c-1); } /** Yields: n! * Precondition: n � 0 */ public static int factorial(int n) { if (n==0) { return 1; } // n > 0 return n*factorial(n-1); } }