/*

A simple multiplication game that times the user on multiplication problems

*/

import java.lang.Math;
import java.io.*;
import java.util.Random;


public class MultiplicationTester {
    
    static public void main(String args[]) {
	
	TimeInterval timer = new TimeInterval();

	BufferedReader reader = 
	    new BufferedReader(new InputStreamReader(System.in));
	
	System.out.print("How many problems would you like to try? ");
	int total;
	try {
	    total = Integer.parseInt(reader.readLine());
	} catch (IOException e) {
	    System.out.println(e);
	    return;
	}

	double totalTime = 0, problemTime;
	Random rand = new Random();
	for (int i=0; i<total; i++) {
	    int A = rand.nextInt(10);
	    int B = rand.nextInt(10);
	    int C = rand.nextInt(10);
	    int answer = A*B*C;

	    System.out.println("What is " + A + "x" + B + "x" + C + "?");

	    timer.startTiming();

	    int response = 0;
	    try {
		response = Integer.parseInt(reader.readLine());
	    } catch (IOException e) {
		System.out.println(e);
	    }

	    while(response != answer) {
		System.out.println("Try again");
		try {		
		    response = Integer.parseInt(reader.readLine());
		} catch (IOException e) {
		    System.out.println(e);
		}
	    }

	    timer.endTiming();

	    problemTime = timer.getElapsedTime();
	    totalTime += problemTime;

	    System.out.println("This problem took you "+problemTime+" seconds");
	    System.out.println("Average time: " + totalTime/(i+1));
	    
	}
    }

}