import java.util.Scanner;

public class MoreMethods {

	public static void main(String[] args) {
		//scope of input: inside main
		Scanner input = new Scanner(System.in);
		
		double x = readDouble(input, "Enter a value for x: ");
		double y = readDouble(input, "Enter a value for y: ");
		
		System.out.printf("%f + %f = %f\n", x, y, x+y);

	} //end main
	
	//readDouble: read a double value from the user.
	// prompt the user too
	// keep asking until a double is entered
	// parameters:
	//   Scanner for the user input
	//   String for the prompt
	// return: the number the user entered.
	public static double readDouble(Scanner in, String prompt) {
		//stub
		//return 1;
		//ask the user
		System.out.print(prompt);
		
		//repeat as long as the user provides a bad input
		// use Scanner's hasNextDouble:
		//     stops the program and waits for user input
		//     eventsreturns true if the user input can be read as a double
		// keep going as long as hasNextDouble is false
		while( !in.hasNextDouble() ) {
			//read the bad input
			String word = in.next();
			System.out.println(word + " is not a number.");
			System.out.print(prompt);
		}
		
		
		//get the value from the user
		double value = in.nextDouble();
		return value;
		
	}
	
} // end MoreMethods
