import java.io.*; public class UserInput { public static int getInt () { int intInput = 0; String userInput = null; // open up standard input BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // read the data from the command-line; need to use try/catch with the // readLine() method try { userInput = br.readLine(); } catch (IOException ioe) { System.out.println("IO error trying to read input!"); System.exit(1); } // convert user input to an integer try { intInput = Integer.parseInt(userInput); } catch (NumberFormatException nfe) { System.out.println("Error: Input provided is not a valid Integer!"); System.exit(1); } return intInput; } public static int getInt (String message) { int intInput = 0; String userInput = null; // prompt the user to enter data System.out.print(message + " "); // open up standard input BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // read the data from the command-line; need to use try/catch with the // readLine() method try { userInput = br.readLine(); } catch (IOException ioe) { System.out.println("IO error trying to read input!"); System.exit(1); } // convert user input to an integer try { intInput = Integer.parseInt(userInput); } catch (NumberFormatException nfe) { System.out.println("Error: Input provided is not a valid Integer!"); System.exit(1); } return intInput; } public static double getDouble () { double doubleInput = 0; String userInput = null; // open up standard input BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // read the data from the command-line; need to use try/catch with the // readLine() method try { userInput = br.readLine(); } catch (IOException ioe) { System.out.println("IO error trying to read input!"); System.exit(1); } // convert user input to a double try { doubleInput = Double.parseDouble(userInput); } catch (NumberFormatException nfe) { System.out.println("Error: Input provided is not a valid Double!"); System.exit(1); } return doubleInput; } public static double getDouble (String message) { double doubleInput = 0; String userInput = null; // prompt the user to enter data System.out.print(message + " "); // open up standard input BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // read the data from the command-line; need to use try/catch with the // readLine() method try { userInput = br.readLine(); } catch (IOException ioe) { System.out.println("IO error trying to read input!"); System.exit(1); } // convert user input to a double try { doubleInput = Double.parseDouble(userInput); } catch (NumberFormatException nfe) { System.out.println("Error: Input provided is not a valid Double!"); System.exit(1); } return doubleInput; } public static String getString () { String userInput = null; // open up standard input BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // read the data from the command-line; need to use try/catch with the // readLine() method try { userInput = br.readLine(); } catch (IOException ioe) { System.out.println("IO error trying to read input!"); System.exit(1); } return userInput; } public static String getString (String message) { String userInput = null; // prompt the user to enter data System.out.print(message + " "); // open up standard input BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // read the data from the command-line; need to use try/catch with the // readLine() method try { userInput = br.readLine(); } catch (IOException ioe) { System.out.println("IO error trying to read input!"); System.exit(1); } return userInput; } } // end of UserInput class