Project 03 Description For this lab you will write a Java pr
Solution
import java.util.*;
public class Project03 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print(\"Enter your name:\");
String name = input.nextLine();//read from the User value
System.out.print(\"Welcome \" + name + \"! Please answer the following questions:\");
int rndmNum1 = (int)(20 * Math.random()) + 1;
int rndmNum2 = (int)(20 * Math.random()) + 1;
int rndmNumAdd = rndmNum1 + rndmNum2;
int rndmNumMul = rndmNum1 * rndmNum2;
int rndmNumDiv = rndmNum1 / rndmNum2;
int rndmNumRem = rndmNum1 % rndmNum2;
int correct = 0;
System.out.print(rndmNum1 + \" + \" + rndmNum2 + \" = \");//check addition
int UsrRndmNumAddVal = input.nextInt();//this is eneterd bythe user
if (UsrRndmNumAddVal == rndmNum1 + rndmNum2) {
System.out.println(\"Correct!\");
correct++; //if correct then increment and store thevalue as we need to provide the percentage
}else {
System.out.println(\"Wrong!\");
System.out.println(\"The correct answer is \" + rndmNumAdd);
}
System.out.print(rndmNum1 + \" * \" + rndmNum2 + \" = \");
int UsrRndmNumMulVal = input.nextInt();//Reads value from user
if (UsrRndmNumMulVal == rndmNum1 * rndmNum2) {
System.out.println(\"Correct!\");
correct++;
}else{
System.out.println(\"Wrong!\");
System.out.println(\"The correct answer is \" + rndmNumMul);
}
System.out.print(rndmNum1 + \" / \" + rndmNum2 + \" = \");//Division
int UsrRndmNumDivVal = input.nextInt();//read result from user
if (UsrRndmNumDivVal == rndmNum1 / rndmNum2) {
System.out.println(\"Correct!\");
correct++;
}else{
System.out.println(\"Wrong!\");
System.out.println(\"The correct answer is \" + rndmNumMul);
}
System.out.print(rndmNum1 + \" % \" + rndmNum2 + \" = \");
int UsrRndmNumRemVal = input.nextInt();//Remainder
if (UsrRndmNumRemVal == rndmNum1 % rndmNum2) {
System.out.println(\"Correct!\");
correct++;
}else{
System.out.println(\"Wrong!\");
System.out.println(\"The correct answer is \" + rndmNumRem);
}
double percentage = correct * 25; //calculate the percentage of correct answers
System.out.println(\"You got \" + correct + \" correct answers\");
System.out.println(\"That\'s \" + percentage + \"%!\");
}
}

