
import java.io.*;

/*   getValueFromInput
 *   Takes as input a String to print to the monitor
 *   Reads characters from the keyboard
 *   Loops until an integer is found; returns that value.
 */    

    public int getValueFromInput(String msg) {

	int num = -1;
	try {

	    String inputLine;
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader keyboard = new BufferedReader(isr);
   	    System.out.print(msg);
	    while ((inputLine = keyboard.readLine()) != null) {
		try {
		    num =  Integer.parseInt(inputLine);
		    return num;
		} catch (NumberFormatException e) {          // user didn't enter a number
		    System.out.println("Enter an integer!"); // give them a message
		    System.out.print(msg);                   // prompt for a new value
		}
	    }
	} catch (IOException ioe) {   // An input/output error happened
	    System.out.println("Problem reading input" + ioe.getMessage());
	}
	return num;

    }
