Question: import java.util.*; import java.math.RoundingMode; import java.text.DecimalFormat; class Easy { // Recursive function to return gcd of a and b public static int calcGCD(int a, int
import java.util.*;
import java.math.RoundingMode;
import java.text.DecimalFormat;
class Easy
{
// Recursive function to return gcd of a and b
public static int calcGCD(int a, int b)
{
if (b == 0)
return a;
return calcGCD(b, a % b);
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
DecimalFormat df = new DecimalFormat("0.00");
char opt='#';int n;
while(opt!='0')
{
int correct=0,wrong=0;
System.out.println(" 1) Quotient 2) Least Common Multiple (LCM) 3) Greatest Common Multiple (GCD) 0) Quit");
opt=sc.next().charAt(0);
switch(opt)
{
case '1':
System.out.print("Number Of Question : ");
n=sc.nextInt();
for(int i=1;i
{
//generate random numbers between [0,150]
int num1 = (int)(Math.random() * (150 - 1 + 1) + 0);
//generate random numbers between [1,40]
int num2 = (int)(Math.random() * (40 - 1 + 1) + 1);
System.out.print("Q"+i+": "+num1+"/"+num2+" = ");
int ans=sc.nextInt();
int correctans=num1um2;
if(ans==correctans)
correct++;
else
wrong++;
}
System.out.println("You have entered "+n+" questions "+correct+" of them are correct. And your mark is "+df.format((double)(correct*100.0))+"%");
break;
case '2':
System.out.print("Number Of Questions : ");
n=sc.nextInt();
for(int i=1;i
{
//generate random numbers between [1,80]
int num1 = (int)(Math.random() * (80 - 1 + 1) + 1);
//generate random numbers between [2,30]
int num2 = (int)(Math.random() * (30 - 1 + 1) + 2);
System.out.print("Q"+i+": LCM ("+num1+","+num2+") = ");
int ans=sc.nextInt();
int correctans=(num1*num2)/calcGCD(num1,num2);
if(ans==correctans)
correct++;
else
wrong++;
}
System.out.println("You have entered "+n+" questions "+correct+" of them are correct. And your mark is "+df.format((double)(correct*100.0))+"%");
break;
case '3':
System.out.print("Number Of Questions : ");
n=sc.nextInt();
for(int i=1;i
{
//generate random numbers between [1,200]
int num1 = (int)(Math.random() * (200 - 1 + 1) + 1);
int num2 = (int)(Math.random() * (200 - 1 + 1) + 1);
System.out.print("Q"+i+": GCD ("+num1+","+num2+") = ");
int ans=sc.nextInt();
int correctans=calcGCD(num1,num2);
if(ans==correctans)
correct++;
else
wrong++;
}
System.out.println("You have entered "+n+" questions "+correct+" of them are correct. And your mark is "+df.format((double)(correct*100.0))+"%");
break;
case '0':
System.out.println("End of Quiz!!");
break;
default:
System.out.println("Invalid Input");
break;
}
}
}
}



L * * * Main Menu * * *4 1) Quotient+ 2) Least Common Multiple (LCM) + 3) Greatest Common Divisor (GCD) + 0} Quit+ >0+ End of Quiz! !+ Add two more choices in the main menu; they are Countprimeand Power. If Countprime is selected, Step 3 generates division questions. If Power is selected, Step 3 generates questions with random operators.+' Operands generated in Countprimeand Power should obey the following rules:+ Operator Operands+ COUNTPRIME+ First operand should be betweenl and 5.+ Second operand should be between6 and 20.+ POWER+ Please random a number C.+ if C is aneven number, please generate: + A10+ B'+C + If C is an odd number, please generate:+ A10_B'+C + A: should be between 1 and 2+ B: should be between 0 and 4+ C: should be between 101 and 1994 Following is a Test Run:+ * * * Main Menu * * *+ 1) Quotient+ 2) Least Common Multiple (LCM) + 3) Greatest Common Divisor (GCD) + 4) Count primes+ 5) Power+ 0) Quit+ Number of Questions : 4+ Q1: Number of primes between 4 and 18 , including bothnumbers ) = 5+ 04: Number of primes between 2 and 8 , including both numbers ) = 4+ You've answered 4 questions+ 4 of them are correct.+ And your mark is 100.00%+ > 5+ Number of Questions : 3+ Q1: 1 ^10 + 0^7 + 124 = 125+ Q2: 2 ^10 + 4^7 + 170 = 17578+ Q3: 1 ^10 - 107 + 159 = 161159+ You've answered 3 questions+ 2 of them are correct.+ And your mark is 66.67%+ * * * Main Menu * * *4 1) Quotient+ 2) Least Common Multiple (LCM) + 3) Greatest Common Divisor (GCD) + 4) Count primes+ 5) Power+ 0) Quit+ > 0+ End of Quiz+ This advanced feature requires you to handle user's invalid input as follow:+ 1. Display meaningful error message, and+ 2. Repeat the same question or menu again unti input is correct.+ This program may have the following input errors:+ InStep 1: Main Menu, users input non integers or input out of range+ 1) Quotient+ 2) Least Common Multiple (LCM) + 3) Greatest Common Divisor (GCD) +4) Count primes+ 5) Power+ 0) Quit+ >X+ Error! Input accept integer only. Input 1-5 or 9.# + 1) Quotient+ 2) Least Common Multiple (LCM) + 3) Greatest Common Divisor (GCD) + 4) Count primes+ 5) Power+ 0) Quit+ 31+ +1 In Step 2: Specify the number of questions, user input non integers.+ Number of Questions: Y+ Error! Input accept integer only.+ Number of Questions: +
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
