/** * Write a description of class ReadNumber here. * * @author John Paxton * @version 1.0 */ import java.io.BufferedReader; import java.io.IOException; public class ReadNumber { /** * This routine asks the user to enter a number between 1 and 10. * @return int - The number between 1 and 10 * @throws IOException - if the stream being read from doesn't exist */ public int getNumber (int lowBound, int highBound, BufferedReader in) throws IOException { String result; int answer = 0; boolean done = false; while (!done) { System.out.print("Enter a number from " + lowBound + " to " + highBound + " > "); result = in.readLine(); try { answer = Integer.parseInt(result); if ((answer >= lowBound) && (answer <= highBound)) { done = true; } else { throw new NumberRangeException("The number you entered is not in range"); } } catch (NumberFormatException exception) { answer = 0; System.out.println(exception); // exception.printStackTrace(); } catch (NumberRangeException exc) { // System.out.println("Error: that number is not in range."); System.out.println(exc); } // finally // { // System.out.println("finally"); // } } return answer; } }