Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can I get help with this java question? Write a class called QuizProgram that si

ID: 3875434 • Letter: C

Question

Can I get help with this java question?

Write a class called QuizProgram that simulates a quiz that helps a young child practice addition and subtraction. The program randomly computes 10 quiz questions which are either addition or subtraction questions in the form of N1-N2 or N1 + N,- guessed answer to the math expression. N1 should be a number from 0 to 99 and N2 should be a number from 0 to N1. The decision to use an addition or subtraction operator in the question should be chosen randomly as well, with equal probability. If the user types in the correct answer, the program should say "You are correct!", otherwise it should print "Sorry, the correct answer is-'. After the 10 questions have been asked, the program should show the % of correct answers where the user tvpes in the Here is example output (colors added for emphasis only) What is the answer to 3 03 You are Correct! What is the answer to 22 - 11 11 You are Correct! What is the answer to 17 - 13 4 You are Correct! What is the answer to 93 21 5 Sorry, the correct answer is 114 What is the answer to 70 12 82 You are correct! What is the answer to 88-4312 Sorry, the correct answer is 45 What is the answer to 88+ 42-130 You are correct! What is the answer to 94-5935 You are correct! What is the answer to 91 + 62-153 You are correct! What is the answer to 6820 48 You are correct! You scored 80% on the quiz

Explanation / Answer

Create a file named Quizprogram.java and paste following java code into it!

Quizprogram.java

import java.io.*;
import java.util.Random;
import java.util.Scanner;
public class Quizprogram {

public static void main(String[] args)
{
Random randomGenerator = new Random();
int score = 0;
for(int i=0;i<10;i++)
{
int randomint = randomGenerator.nextInt(2);   
int N1 = randomGenerator.nextInt(100);
int N2 = randomGenerator.nextInt(N1);

Scanner scanner = new Scanner(System.in);   
if(randomint == 0)//addition
{
System.out.print("What is the answer to " + N1 + " + " + N2 + " = ");
int input = scanner.nextInt();
if(input == (N1 + N2))
{
score = score + 10;
System.out.println("You are correct!");
}
else
{
System.out.println("Sorry, the correct answer is " + (N1 + N2));   
}
  
}
else //subtraction
{
System.out.print("What is the answer to " + N1 + " - " + N2 + " = ");
int input = scanner.nextInt();
if(input == (N1 - N2))
{
score = score + 10;
System.out.println("You are correct!");
}
else
{
System.out.println("Sorry, the correct answer is " + (N1 - N2));   
}


}
}
System.out.println("You scored " + score + " % on the quiz!");
}   
}

Sample Output:

What is the answer to 20 - 5 = 15
You are correct!
What is the answer to 86 - 9 = 77
You are correct!
What is the answer to 37 + 16 = 53
You are correct!
What is the answer to 94 - 85 = 9
You are correct!
What is the answer to 60 + 1 = 61
You are correct!
What is the answer to 54 + 17 = 71
You are correct!
What is the answer to 57 - 5 = 50
Sorry, the correct answer is 52
What is the answer to 27 - 9 = 40
Sorry, the correct answer is 18
What is the answer to 59 + 34 = 4
Sorry, the correct answer is 93
What is the answer to 95 - 8 = 87
You are correct!
You scored 70% on the quiz!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote