// Zorah Fung, CSE 142 // A begining draft of a game that gives the user // randomly generated math expressions to solve. // NOTE: This is incomplete and will be finished on Monday! import java.util.*; public class AdditionGame { public static void main(String[] args) { Scanner console = new Scanner(System.in); Random rand = new Random(); int misses = 0; while (misses < 3) { int point = playGame(console, rand); if (point == 0) { misses++; } } } // Asks the user to solve a single randomly generated mathematical expression // Uses the given Random to randomly generate the expression. Takes input // using the given Scanner. public static int playGame(Scanner console, Random rand) { int operands = rand.nextInt(4) + 2; int actualSum = 0; for (int i = 1; i <= operands - 1; i++) { int number = rand.nextInt(31); System.out.print(number + " + "); actualSum += number; } int lastNumber = rand.nextInt(31); actualSum += lastNumber; System.out.print(lastNumber + " = "); // System.out.print("hint: " + actualSum + " "); For debugging int guess = console.nextInt(); if (actualSum != guess) { System.out.println("Wrong! The answer was " + actualSum); return 0; } return 1; } }