// Arup Guha
// 2/11/2017
// Solution to one fraction exercise

import java.util.*;

public class fractiongame {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		Random r = new Random();

		System.out.println("How many problems do you want?");
		int numProbs = stdin.nextInt();

		int score = 0;

		// Go through problems.
		for (int i=0; i<numProbs; i++) {

			// Create the first fraction.
			int n1 = r.nextInt(10);
			int n2 = 1 + r.nextInt(10);
			fraction f1 = new fraction(n1, n2);

			// Create the second fraction.
			n1 = r.nextInt(10);
			n2 = 1 + r.nextInt(10);
			fraction f2 = new fraction(n1, n2);

			// Randomly generate which operation we want.
			int op = r.nextInt(4);

			// Perform addition.
			if (op == 0) {

				// Ask the question, get the response and calculate the correct answer.
				System.out.println("What is "+f1+" + "+f2+"?");
				String res = stdin.next();
				fraction ans = new fraction(res);
				fraction correct = f1.add(f2);

				// See if they got it!
				if (ans.equals(correct)) {
					System.out.println("Great, you got it!");
					score++;
				}
				else {
					System.out.println("That's not correct. The answer is "+correct);
				}
			}

			// Subtraction
			else if (op == 1) {

				// Ask the question, get the response and calculate the correct answer.
				System.out.println("What is "+f1+" - "+f2+"?");
				String res = stdin.next();
				fraction ans = new fraction(res);
				fraction correct = f1.sub(f2);

				// See if they got it!
				if (ans.equals(correct)) {
					System.out.println("Great, you got it!");
					score++;
				}
				else {
					System.out.println("That's not correct. The answer is "+correct);
				}
			}

			// Multiplication
			else if (op == 2) {

				// Ask the question, get the response and calculate the correct answer.
				System.out.println("What is "+f1+" * "+f2+"?");
				String res = stdin.next();
				fraction ans = new fraction(res);
				fraction correct = f1.mult(f2);

				// See if they got it!
				if (ans.equals(correct)) {
					System.out.println("Great, you got it!");
					score++;
				}
				else {
					System.out.println("That's not correct. The answer is "+correct);
				}
			}

			// Division
			else {

				// Ask the question, get the response and calculate the correct answer.
				System.out.println("What is "+f1+" / "+f2+"?");
				String res = stdin.next();
				fraction ans = new fraction(res);
				fraction correct = f1.div(f2);

				// See if they got it!
				if (ans.equals(correct)) {
					System.out.println("Great, you got it!");
					score++;
				}
				else {
					System.out.println("That's not correct. The answer is "+correct);
				}

			}

		} // end game.

		// Output results.
		System.out.println("You got "+score+" questions out of "+numProbs+" for a percentage of "+(100.0*score/numProbs));
	}

}