Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m having problems with writing this code in java. Arithmetic Quiz The objecti

ID: 3791484 • Letter: I

Question

I'm having problems with writing this code in java.

Arithmetic Quiz

The objective of this assignment is to gain experience writing decision statements and loops.

You have just been hired as a teacher’s aide in the School of Math, grade 3. Your students need extra practice with their arithmetic skills, and you have been given the task of writing a computer program that will allow them to practice on their own. The specific requirements of the project are as follows:

Display the menu shown below and get the user’s choice. If the user does not enter a valid choice, output an appropriate message and prompt for another choice.

Please choose one of the following options for your math quiz:

1. Addition with numbers 1­10

2. Addition with numbers 1­100

3. Subtraction with numbers 1­10

4. Subtraction with numbers 1­100

5. Multiplication with numbers 1­10

6. Exit the program

If the user chooses one of the first five menu options, display five problems of the requested type to the user. For example, if the user chooses option 1, your program should display five addition problems, one at a time, using randomly randomly generated operands between 1 and 10. After each problem, your program should read the user’s answer and display an appropriate error message: either “That is the correct answer!” or “Sorry, that is incorrect. The correct answer is X”, where X is the correct answer to the arithmetic problem.

If the user chooses the last menu option, the program should output the number of problems correct, the number of problems tried, and the percentage of problems correct to 2 decimal places before terminating.

Hint: You can use the following formula to generate random numbers:

(int)(lowerBound + Math.random() * (upperBound – lowerBound + 1))

You may use literals in place of the upper and lower bounds. For instance, to display values between 1 and 10 (inclusive on both ends), the formula would look like this:

(int)(1 + Math.random() * 10)

Explanation / Answer

Hi buddy, please find the below java program.

import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
   public static void main (String[] args) throws java.lang.Exception
   {
       // your code goes here
       Scanner obj = new Scanner(System.in);
       Random r = new Random();
       int total = 0;
       int correct = 0;
       while(true){
            System.out.println("Please choose one of the option for your math quiz:");
            System.out.println("1. Addition with numbers 1 ­10");
            System.out.println("2. Addition with numbers 1 ­100");
            System.out.println("3. Subtraction with numbers 1 ­10");
            System.out.println("4. Subtraction with numbers 1 ­100");
            System.out.println("5. Exit");
            int ch = obj.nextInt();
            if(ch==1){
                for(int i=0;i<5;i++){
                    total++;
                    int a = r.nextInt(10)+1;
                    int b = r.nextInt(10)+1;
                    System.out.println(a+" + "+b+" = ?");
                    int ans = obj.nextInt();
                    if(ans==a+b){
                        System.out.println("That is the correct answer!");
                        correct++;
                    }
                    else{
                        System.out.println("Sorry, that is incorrect. The correct answer is "+(a+b));
                    }
                }
            }
            else if(ch==2){
                for(int i=0;i<5;i++){
                    total++;
                    int a = r.nextInt(100)+1;
                    int b = r.nextInt(100)+1;
                    System.out.println(a+" + "+b+" = ?");
                    int ans = obj.nextInt();
                    if(ans==a+b){
                        System.out.println("That is the correct answer!");
                        correct++;
                    }
                    else{
                        System.out.println("Sorry, that is incorrect. The correct answer is "+(a+b));
                    }
                }
            }
            else if(ch==3){
                for(int i=0;i<5;i++){
                    total++;
                    int a = r.nextInt(10)+1;
                    int b = r.nextInt(10)+1;
                    System.out.println(a+" - "+b+" = ?");
                    int ans = obj.nextInt();
                    if(ans==a-b){
                        System.out.println("That is the correct answer!");
                        correct++;
                    }
                    else{
                        System.out.println("Sorry, that is incorrect. The correct answer is "+(a-b));
                    }
                }
            }
            else if(ch==4){
                for(int i=0;i<5;i++){
                    total++;
                    int a = r.nextInt(100)+1;
                    int b = r.nextInt(100)+1;
                    System.out.println(a+" - "+b+" = ?");
                    int ans = obj.nextInt();
                    if(ans==a-b){
                        System.out.println("That is the correct answer!");
                        correct++;
                    }
                    else{
                        System.out.println("Sorry, that is incorrect. The correct answer is "+(a-b));
                    }
                }
            }
            else{
                break;
            }
       }
       System.out.println("Total number of problems tried "+total);
       System.out.println("Number of problems correct "+correct);
       System.out.println("Percentage of problems correct "+(correct*100d)/(total*1d));
   }
}

OUTPUT :

Please choose one of the option for your math quiz:
1. Addition with numbers 1 ??10
2. Addition with numbers 1 ??100
3. Subtraction with numbers 1 ??10
4. Subtraction with numbers 1 ??100
5. Exit
1
6 + 1 = ?
7
That is the correct answer!
2 + 4 = ?
6
That is the correct answer!
1 + 4 = ?
3
Sorry, that is incorrect. The correct answer is 5
1 + 8 = ?
99
Sorry, that is incorrect. The correct answer is 9
8 + 2 = ?
10
That is the correct answer!
Please choose one of the option for your math quiz:
1. Addition with numbers 1 ??10
2. Addition with numbers 1 ??100
3. Subtraction with numbers 1 ??10
4. Subtraction with numbers 1 ??100
5. Exit
4
11 - 87 = ?
-76
That is the correct answer!
46 - 20 = ?
26
That is the correct answer!
50 - 80 = ?
-30
That is the correct answer!
41 - 30 = ?
11
That is the correct answer!
21 - 82 = ?
61
Sorry, that is incorrect. The correct answer is -61
Please choose one of the option for your math quiz:
1. Addition with numbers 1 ??10
2. Addition with numbers 1 ??100
3. Subtraction with numbers 1 ??10
4. Subtraction with numbers 1 ??100
5. Exit
5
Total number of problems tried 10
Number of problems correct 7
Percentage of problems correct 70.0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote