Question

Need a program in java that creates a random addition math quiz The program should ask...

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

0 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

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 correct=0;
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("**********************************************************");
}
  
  
}
}

Add a comment
Know the answer?
Add Answer to:
Need a program in java that creates a random addition math quiz The program should ask...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT