In: Other
Need a program in java that creates a random addition math quiz
The program should ask the user to enter the following
The smallest and largest positive numbers to be used when generating the questions -
The total number of questions to be generated per quiz -
The total number of the quiz's to create
from then the program should generate a random math (Just addition) quiz from what the user entered
Here is the code for above problem in Java:
import java.util.Scanner;
import java.util.Random;
public class Main{
public static void main(String []args){
int correct=0;
Scanner input=new Scanner(System.in);
System.out.println("Enter your name: ");
String name=input.nextLine();
System.out.println("Welcome "+name+" ,Please answer the following
questions: ");
System.out.println("Smallest number to be used in quiz: ");
int min=input.nextInt();
System.out.println("Largest number to be used in quiz: ");
int max=input.nextInt();
System.out.println("Total number of questions in a quiz: ");
int totalques=input.nextInt();
System.out.println("Total number of quizzes to create: ");
int totalquizzes=input.nextInt();
Random r = new Random();
for(int i=0;i
System.out.println("Lets start the quiz: ");
for(int j=0;j
int r1=r.nextInt((max - min) + 1) + min;
int r2=r.nextInt((max - min) + 1) + min;
int r3=r1+r2;
System.out.print(r1 + " + " + r2 + " = ");
int GuessRandomNumberAdd = input.nextInt();
if (GuessRandomNumberAdd == r1 + r2){
System.out.println("Correct!");
correct++;
}else{
System.out.println("Wrong!");
System.out.println("The correct answer is " + r3);
}
}
double percentage = (correct * 100)/totalques;
System.out.println("The percentage is " + percentage);
System.out.println("**********************************************************");
}
}
}