/* EXPECTED OUTPUT: This program helps you practice multiplication by asking you random multiplication questions with numbers ranging from 1 to 20 and counting how many you solve correctly. 14 * 8 = 112 Correct! 5 * 12 = 60 Correct! 8 * 3 = 24 Correct! 5 * 5 = 25 Correct! 20 * 14 = 280 Correct! 19 * 14 = 256 Incorrect; the correct answer was 266 You solved 5 correctly. */ import java.util.*; // Asks the user to do multiplication problems and scores them. public class MultTutor { public static final int MAX = 20; public static void main(String[] args) { introduction(); Scanner console = new Scanner(System.in); // loop until user gets one wrong int correct = 0; while (askQuestion(console)) { correct++; } System.out.println("You solved " + correct + " correctly."); } public static void introduction() { System.out.println("This program helps you practice multiplication"); System.out.println("by asking you random multiplication questions"); System.out.println("with numbers ranging from 1 to " + MAX); System.out.println("and counting how many you solve correctly."); System.out.println(); } public static boolean askQuestion(Scanner console) { // pick two random numbers between 1 and 20 inclusive Random rand = new Random(); int num1 = rand.nextInt(MAX) + 1; int num2 = rand.nextInt(MAX) + 1; System.out.print(num1 + " * " + num2 + " = "); int guess = console.nextInt(); if (guess == num1 * num2) { System.out.println("Correct!"); return true; } else { System.out.println("Incorrect; the correct answer was " + (num1 * num2)); return false; } } }