import java.util.Scanner;

public class MoreMethods {

	public static void main(String[] args) {
		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: reads a double value from the user input.
	// prompt the user (ask the question)
	// read a number
	// repeat if the user input is wrong
	// parameters:
	//    Scanner to read the values	//    String the prompt
	// return value: a double value entered by the user
	public static double readDouble(Scanner in, String prompt) {
		//stub
		//return 1;
		//ask the user
		System.out.print(prompt);
		
		//repeat: keep asking until they type the right thing
		//  use Scanner's hasNextDouble method
		//   stops and waits for input to be available
		//   if the input can be read as a double, return true
		//      false otherwise
		// DOES NOT read a value
		while( !in.hasNextDouble()) {
			//get rid of the bad input
			String word = in.next();
			
			//error message
			System.out.println(word + " is not a number.");
			//prompt again
			System.out.print(prompt);
		}
		
		
		//read the value
		double value = in.nextDouble();
		return value;
	}
	
	
} //end class MoreMethod
