class flashcards extends basic { // Main program to monitor a series of flashcard practice sessions public static void main (String[] args) throws Exception { input in = new input(); output out = new output(); String answer=""; int n=0; out.write("Do you want a flashcard drill (y or n)?"); answer = in.readword(); while (answer.equals("y")) { out.write("How many flashcards do you want to see?"); n = in.readint(); int nCorrect = Practice(in, out, n); out.writeln ("You have solved " + nCorrect + " out of " + n + " problems correctly!"); out.write("Do you want another drill (y or n)?"); answer = in.readword(); } } // Monitor a practice session for a series of 'nCards' problems; // return the number of problems that the user solves correctly. static int Practice (input in, output out, int nCards) throws Exception { int c = 0, max = 100; random select = new random(1,max); for (int i=1; i<=nCards; i++) { int a = select.readint(); int b = select.readint(); boolean gotItRight = SolveProblem(in, out, a, b); if (gotItRight) c = c + 1; } return c; } // Monitor a single interaction for the problem 'a + b' // and return 'true' if the answer is correct. static boolean SolveProblem (input in, output out, int a, int b) throws Exception { out.writeln("What is " + a + " + " + b + "?"); int sum = in.readint(); if (sum != a+b) { out.writeln(sum + " is incorrect"); return false; } else { out.writeln(sum + " is correct"); return true; } } }