/* * Making sure that the user input is in range * @param1 Scanner object for input * @param2 lowerbound integer * @param3 upperbound integer * @param4 String that specifies for which attribute/field input is for * printing purposes * @param5 ValType enum that specifies whether the primitive value is * an int or double * @param6 boolean that specifies whether the input is an Enum value * @param7 boolean that specifies whether to return the value if out of * range (false) or not (true) */ public static Number makeSureValInRange( Scanner input, int lowerbound, int upperbound, String inputFor, ValType valType, boolean enumeration, boolean withinRange) { boolean valid = !withinRange; Number val = 0; while (!valid) { System.out.println(inputString(inputFor, null, StringOption.SELECT, enumeration)); val = valType == ValType.INTEGER ? input.nextInt() : input.nextDouble(); if (val.intValue() < lowerbound || val.intValue() > upperbound) { System.out.println(inputString(inputFor, null, StringOption.INCORRECT, enumeration)); } else { valid = true; } } return val; }