/** * This method asks a question and ranges checks the response. * The method will not terminate until an integer in the range * is given. * * NOTE: this method ONLY accepts integer responses * (future dev: allow for other type response) * * @author: Dave Slemon * * @param c points to the canvas * @param question is the question prompt * @param low is the lowest allowed response * @param high is the highest allowed response * * @return Returns the integer response to the question. */ public int askQuestion( Console c, String question, int low, int high) { int result = 1; boolean ok = true; do { c.print(question + " (accepted range: " + low + " to " + high +") > " ); result = c.nextInt(); ok = (result >= low) && (result <= high); // *** an error message shown for invalid responses if (!ok) { c.print("RANGE ERROR: " ); } } while ( !ok ); return result; }