Question: import java.util.Scanner; // Needed for the Scanner class import java.util.Random; // Needed for the Random class /** This program demonstrates the Random class. */ public
import java.util.Scanner; // Needed for the Scanner class
import java.util.Random; // Needed for the Random class
/**
This program demonstrates the Random class.
*/
public class MathTutor
{
public static void main(String[] args)
{
int number1; // A number
int number2; // Another number
int sum; // The sum of the numbers
int userAnswer; // The user's answer
// Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
// Random class object.
Random randomNumbers = new Random();
// Get two random numbers.
number1 = randomNumbers.nextInt(100);
number2 = randomNumbers.nextInt(100);
// Display an addition problem.
System.out.println("What is the answer to the " +
"following problem?");
System.out.print(number1 + " + " +
number2 + " = ? ");
// Calculate the answer.
sum = number1 + number2;
// Get the user's answer.
userAnswer = keyboard.nextInt();
// Display the user's results.
if (userAnswer == sum)
System.out.println("Correct!");
else
{
System.out.println("Sorry, wrong answer. " +
"The correct answer is " +
sum);
}
}
}Complete the above Java project.Please do not use global variables. Do not write OOP programs.
Step 1
In the main method, generate a random operator (+, -, *, /, or %).
The program should be able to perform addition, subtraction, multiplication, division (both quotient and remainder) on two integers.
Step 2
Write the first method to calculate and return the result. The method has three parameters: operand 1, operand 2, and operator.
Write the second method to evaluate the student's answer to determine whether or not the student's answer is correct, then return the status (True or False). The method has two parameters: the correct answer and the student's answer.
In the main method, generate two random integers and a random operator (+, -, *, /, or %), then call the first method to calculate the result. Next, prompt the student to enter an answer, call the second method to evaluate the student's answer and print a message. If the student's answer is incorrect, the correct answer should be given. The message should be printed in the main method, not in the second method.
Step 3
Use a loop to continue to run until the student choose not to.
In the end, print the total number of questions, number of correct answers, and the percentage of correct answers.
Sample Run:
Welcome to Math Tutor Program
*******************************************
What is the answer to the following problem?
83 - 67 = ? 16
Correct!
Do you want to continue (Yes to continue)? Yes
What is the answer to the following problem?
16 * 7 = ? 102
Sorry, wrong answer. The correct answer is 112.
Do you want to continue (Yes to continue)? Yes
What is the answer to the following problem?
9 % 5 = ? 1.8
Sorry, wrong answer. The correct answer is 4.
Do you want to continue (Yes to continue)? No
********************************************
Total Questions: 3
Correct Answers: 1
Grade Percentage: 33%
Thank you for using the program.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
