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

Please answer in Java code and use Math.random and scanner class, and do not use

ID: 3875398 • Letter: P

Question

Please answer in Java code and use Math.random and scanner class, and do not use random class

(1) Quiz Program 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 N N2or N N2where the user types in the guessed answer to the math expression. N1 should be a number from 0 to 99 and N2 should be a number from 0 to N. 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. Here is example output (colors added for emphasis only): What is the answer to 3 +0=3 You are correct! 11 What is the answer to 22-11 You are correct! 4 What is the an wor to 17-13 You are correct What is the answer to 93 + 21·5 Sorry, the correct answer is 114 82 What is the answer to 70 + 12 You are correct! What is the answer to 88-43 12 Sorry, the correct answer is 45 130 What is the answer to 88 + 42 You are correct! 35 What is the answor to 94-59 You are correct! 153 What is the answer to 91 + 62 You are correct What is the answer to 68-20 = 48 You are correct! You scored 80% on the quiz

Explanation / Answer

/******************************************************************************

Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/

import java.lang.*;
import java.util.Scanner;

public class Main {

public static void main(String[] args) {

// get two random double numbers
Scanner s=new Scanner( System.in);
int operator=(int)Math.random()*2;
int correct_answers=0;
for(int i=1;i<=10;i++)
{
int N1 = (int)(Math.random()*98)+1;//N1 random
int N2 =(int) (Math.random()*99)%N1;//N2 Random value
int result;
// int operator=(int)Math.random()*2;
if(operator==0)
{ result=N1+N2;
System.out.print("What is the answer to "+N1+" + "+N2+"=");
operator=1;
}
else{ result=N1-N2;
System.out.print("What is the answer to "+N1+" - "+N2+"=");
operator=0;
}
int input=s.nextInt();
if(input==result) {
System.out.println("You are correct");
correct_answers++;
}else
System.out.println(" sorry, the correct answer is "+result);
}
System.out.println(" you scored "+correct_answers*10+"% on the Quiz");
  
}
}