Question

In: Other

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

Solutions

Expert Solution

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


Related Solutions

java program Create a program that creates and prints a random phone number using the following...
java program Create a program that creates and prints a random phone number using the following format: XXX-XXX-XXXX. Make sure your output include the dashes.  Do not let the first three digits contain an 8 or 9 (HINT: do not be more restrictive than that) and make sure that the second set of three digits is not greater than 773. Helpful Hint:   Think though the easiest way to construct the phone number. Each digit does do not have to be determined...
Exercise Overview Implement a Java program that creates math flashcards for elementary grade students. User will...
Exercise Overview Implement a Java program that creates math flashcards for elementary grade students. User will enter his/her name, the type (+, -, *, /), the range of the factors to be used in the problems, and the number of problems to work. The system will provide problems, evaluate user responses to the problems, score the problems, and provide statistics about the session at the end. Functional Requirements User enters name at the beginning of a session. System covers four...
C++ polymorphism. Create a program that issues a quiz through the terminal. The quiz will ask...
C++ polymorphism. Create a program that issues a quiz through the terminal. The quiz will ask a variety of C++ questions to the user and prompt them for a response. The response will differ based on the type of question, such as true or false, multiple-choice, or fill in the blank. Part 1: Designing the Quiz Design this program using a polymorphic vector of questions. Create a Question base class that will serve to point to three different derived classes:...
Write a Java program that creates an array with 20 random numbers between 1 and 100,...
Write a Java program that creates an array with 20 random numbers between 1 and 100, and passes the array to functions in order to print the array, print the array in reverse order, find the maximum element of the array, and find the minimum element of the array. The prototype of the methods: public static void printArray(int arr[]) public static void printArrayReverse(int arr[]) public static int searchMax(int arr[]) public static int searchMin(int arr[]) Sample output: Random Array: [17 67...
The JAVA program should do the following: –Ask the user for how many lines of text...
The JAVA program should do the following: –Ask the user for how many lines of text they wish to enter –Declare and initialize an array of Strings to hold the user’s input –Use a while loop to prompt for and read the Strings (lines of text) from the user at the command line. Typically, this would be a 'for' loop since we know the number of times to execute the loop based upon the number supplied by the user, but...
Input, output, and math Draw a diagram for a program that: 1. Creates a variable called...
Input, output, and math Draw a diagram for a program that: 1. Creates a variable called tspBakingSoda, stores 1 in it. 2. Creates a variable called tspBakingPowder, stores 0.5 in it. 3. Creates a variable called cupsButter, stores 1 in it. 4. Creates a variable called cupsWhiteSugar, stores 1.5 in it. 5. Creates a variable called totalEggs, stores 1 in it. 6. Ask the user "how many batches?", store in a variable called batches. 7. Multiply tspBakingSoda by batches 8....
Write a Java Program to place a pizza ordering program. It creates a pizza ordered to...
Write a Java Program to place a pizza ordering program. It creates a pizza ordered to the specifications that the user desires. It walks the user through ordering, giving the user choices, which the program then uses to decide how to make the pizza and how much the cost of the pizza will be. Note: Use dialog boxes for communicating with the user. Remember to use the JOptionPane class which is the graphical user interface (GUI) and Comments that are...
Write a Java Program to place a pizza ordering program. It creates a pizza ordered to...
Write a Java Program to place a pizza ordering program. It creates a pizza ordered to the specifications that the user desires. It walks the user through ordering, giving the user choices, which the program then uses to decide how to make the pizza and how much the cost of the pizza will be. Note: Use dialog boxes for communicating with the user. Remember to use the JOptionPane class which is the graphical user interface (GUI) and Comments that are...
Write a java program that will ask for a Star Date and then convert it into...
Write a java program that will ask for a Star Date and then convert it into the corresponding Calendar date. without using array and methods.
Give an example of a program in java that creates a GUI with at least one...
Give an example of a program in java that creates a GUI with at least one button and several textfields. Some of the textfields should be for input and others for output. Make the output textfields uneditable. When the button is clicked, the input fields should be read, some calculation performed and the result displayed in the output textfield(s).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT