import java.io.*;

/**
 * This class holds static methods to talk to the user.  All exception
 * handling is encapsulated in these methods.
 */
class UserTalker {

    // Gets a valid int from the user
    public static int getInteger(String prompt, BufferedReader stdin) {
	
	int number = 0;
	boolean valid = false;

	while(!valid) {
	    System.out.print(prompt);
	    try {
		number = Integer.parseInt(stdin.readLine());
		valid = true;
	    }
	    catch (NumberFormatException nfe) {
		System.out.println("Invalid Input.  Try again.");
	    }
	    catch (IOException ioe) {
		System.out.println("Error in Input.  Terminating.");
		System.exit(0);
	    }
	}
	return number;
    }
    
    // Gets a valid color from the user.
    public static String getColor(String prompt, BufferedReader stdin) {
	
	String color = null;
	boolean valid = false;
	
	while (!valid) {
	    System.out.print(prompt);
	    try {
		color = stdin.readLine();
		if (color.equals("GREEN") || color.equals("RED") ||
		    color.equals("BLUE") || color.equals("YELLOW")) {
		    valid = true;
		}
		else {
		    System.out.println("Valid colors are RED, GREEN, BLUE, " +
				       "and YELLOW");
		}
	    }
	    catch (IOException ioe) {
		System.out.println("Error in Input.  Terminating.");
		System.exit(0);
	    }
	}
	return color;
    }
}
