Project 03 Description For this lab you will write a Java pr

Project 03 Description For this lab you will write a Java program that will run a simple math quiz. Your program will generate two random integers between 1 and 20 and then ask a series of math questions. Each question will be evaluated as to whether it is the right or wrong answer. In the end a final score should be reported for the user. Following the instructions from Closed Lab 01, create a new folder named Project03 and a new Java program in that folder named Project03.java for this assignment. Project 03 Sample ouptut This is a sample transcript of what your program should do. Items in bold are user input and should not be put on the screen by your program. Enter your name Jeremy Welcome Jeremy Please answer the following questions 4 6 10 Correct. 4 6 24 Correct! Wrong! The correct answer is 0 4 6 Correct! You got 3 correct answers That\'s 75.08

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 + \"%!\");

        }

}

 Project 03 Description For this lab you will write a Java program that will run a simple math quiz. Your program will generate two random integers between 1 an
 Project 03 Description For this lab you will write a Java program that will run a simple math quiz. Your program will generate two random integers between 1 an

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site