Answer:
A java program was used to run a simple math quiz. the program was used to generate two random integers between 1 and 20 and then ask a series of math questions
Step-by-step explanation:
Solution
THE CODE:
import java.util.Random;
import java.util.Scanner;
public class LabQuiz {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("****Welcome to Quiz******");
System.out.print("Enter your name: ");
String name = in.next();
System.out.println("Welcome "+name+"! Please answer the following questions:");
int scoreCounter=0;
int a;
int b;
int response;
a=getRandomNum();
b=getRandomNum();
System.out.print(a+"+"+b+"=");
response = in.nextInt();
if(response==(a+b)){
scoreCounter++;
System.out.println("That is correct");
}
else
System.out.println("No, thats not the right answer, its::"+(a+b));
a=getRandomNum();
b=getRandomNum();
System.out.print(a+"*"+b+"=");
response = in.nextInt();
if(response==(a*b)){
scoreCounter++;
System.out.println("That is correct");
}
else
System.out.println("No, thats not the right answer, its::"+(a*b));
a=getRandomNum();
b=getRandomNum();
System.out.print(a+"/"+b+"=");
response = in.nextInt();
if(response==(a/b)){
scoreCounter++;
System.out.println("That is correct");
}
else
System.out.println("No, thats not the right answer, its::"+(a/b));
a=getRandomNum();
b=getRandomNum();
System.out.print(a+"%"+b+"=");
response = in.nextInt();
if(response==(a%b)){
scoreCounter++;
System.out.println("That is correct");
}
else
System.out.println("No, thats not the right answer, its::"+(a*b));
System.out.println("You got "+scoreCounter+" correct answers.");
System.out.println("Thats "+(scoreCounter*25)+"%");
in.close();
}
static int getRandomNum(){
Random rand = new Random();
int a;
a = rand.nextInt(20);
if(a==0)
a++;
return a;
}
}