// EmptyProgram.java // // Start with this shell when writing a program from scratch. class EmptyProgram { public static void main(String[] args) { // your code here! } /////////////////////////////////////////////// // readString, readInt, readDouble, readBoolean /////////////////////////////////////////////// public static String readString() { java.io.InputStreamReader isr = new java.io.InputStreamReader(System.in); java.io.BufferedReader d = new java.io.BufferedReader(isr); try { return d.readLine(); } catch (Exception e) { return "error"; } } public static int readInt() { while (true) { try { return Integer.parseInt(readString()); } catch (Exception e) { System.out.print("Error. Try again. Please enter an integer: "); } } } public static double readDouble() { while (true) { try { return Double.parseDouble(readString()); } catch (Exception e) { System.out.print("Error. Try again. Please enter a double: "); } } } public static boolean readBoolean() { while (true) { String reply = readString().toLowerCase(); if (reply.equals("true")) return true; if (reply.equals("false")) return false; System.out.print("Error. Try again. Please enter 'true' or 'false': "); } } }