Question
Exercise 2. ( Problem: An Advanced Math Learning Tool) The Math subtraction learning tool program generates just one question for each run. To create one
Exercise 2. (Problem: An Advanced Math Learning Tool) The Math subtraction learning tool program generates just one question for each run. To create one question, the program randomly generates two integers between 0 and 99, say, number1 and number2, and displays a question such as What is number1 * number2? to the student, namely asking for the product of the two numbers. After the student types the answer, the program displays a message to indicate whether the answer is true or false. You can use a loop to generate questions repeatedly. Write a Java program that generates five questions and reports the number of the correct answers after a student answers all five questions.
How to create the loop for the program? here is what i have
Scanner input = new Scanner(System.in);
int number1 = (int)(Math.random() * 100);
int number2 = (int)(Math.random() * 100);
if (number1 < number2) {
int temp = number1;
number1 = number2;
number2 = temp;
}
System.out.println("What is " + number1 + "-" + number2 + "?");
int answer = input.nextInt();
if (number1 - number2 == answer)
System.out.println("YOU ARE CORRECT, YOU GET A STAR!");
else
System.out.println("Your answer is wrong, You get no star. " + number1 + " - " + number2 + " should be " + (number1 -number2));
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started