package lab8;

public class Input {
	private Input(){}

	/**
	 * try to parse a number from string
	 * precondition : the String must contain number and the value must be between min and max
	 * @param prompt	as String to parse as number
	 * @param error		as String to Throw on error
	 * @param min		as int minimum allowed value
	 * @param max		as int maximum value
	 * @return			int as parsed value
	 * @throws NumberFormatException if String value not an number or min and max not respected
	 */
	public static int readInt (String prompt, String error, int min, int max) throws NumberFormatException{
		int tmp;
		try{
			tmp = Integer.parseInt(prompt);
		}catch(NumberFormatException e){
			throw new NumberFormatException(error);
		}
		if (tmp > max || tmp < min)
			throw new NumberFormatException(error);
		return tmp;
	}
}
