1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vichka [17]
3 years ago
15

For this project 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. (See below for how to generate random numbers).Following the instructions from Closed Lab 01, create a new folder named FunWithBranching and a new Java program in that folder named FunWithBranching.java for this assignment.Sample Ouptut This is a sample transcript of what your program should do. Values in the transcript in BOLD show the user inputs. So in this transcript the user inputs 33, Jeremy, 24, -16, 80 and 0 - the rest is output from the program.Enter a random number seed: 33Enter your name: JeremyHello Jeremy!Please answer the following questions:4 + 20 = 24Correct!4 - 20 = -16Correct!4 * 20 = 80Correct!4 / 20 = 0Correct!4 % 20 = 4Correct!You got 5 correct answers!That's 100.0%!Your code will behave differently based on the random number seed you use and the answers provided by the user. Here is a second possible execution of this code. As before, values in BOLD are provided by the user - in this case 54, Bob, 8, 32, 8 and 1 - the rest is the output of the program when you run it.Enter a random number seed: 54Enter your name: BobHello Bob!Please answer the following questions:20 + 12 = 8Wrong!The correct answer is: 3220 - 12 = 32Wrong!The correct answer is: 820 * 12 = 8Wrong!The correct answer is: 24020 / 12 = 1Correct!20 % 12 = 8Correct!You got 2 correct answers!That's 40.0%!

Computers and Technology
1 answer:
ElenaW [278]3 years ago
3 0

Answer:

Here is the JAVA program:

import java.util.Scanner;   //to accept input from user

public class FunWithBranching {   //class name

   public static void main(String[] args) {  //start of main function

   Scanner input = new Scanner(System.in);  //creates Scanner object

   System.out.print("Enter your name: "); //prompts user to enter name

   String userName = input.nextLine();  //stores the name

   System.out.print("Welcome " + userName + "! Please answer the following questions:\n");   //prompts user to answer the questions

   int randomOperand1 =  (int)(20 * Math.random()) + 1;  //generates random number for operand 1 (1-20)

   int randomOperand2 =  (int)(20 * Math.random()) + 1;  //generates random number for operand 2 (1-20)

   int randomAdd = randomOperand1 + randomOperand2;  //performs addition of two random numbers and stores result in randomAdd

   int randomMul = randomOperand1 * randomOperand2;  //performs multiplication of two random numbers

   int randomDiv = randomOperand1 / randomOperand2;  //performs division of two random numbers

   int randomMod = randomOperand1 % randomOperand2;  //performs modulo of two random numbers

   int correctAns = 0;  //stores number of correct answers

   System.out.print(randomOperand1 + " + " + randomOperand2 + " = ");  //displays random number + random number

   int AdditionGuess = input.nextInt();   //reads the answer of addition from user and stores it in AdditionGuess

   if (AdditionGuess == randomOperand1 + randomOperand2) {  //if the user answer is correct

   System.out.println("Correct!");  //displays correct

   correctAns++;  //adds 1 to the count of correctAns every time the user gives correct answer of addition

 } else {  //if user answer is incorrect

   System.out.println("Wrong!");  //displays wrong

   System.out.println("The correct answer is " + randomAdd);   }  //displays the correct answer of addition

   System.out.print(randomOperand1 + " * " + randomOperand2 + " = ");  //displays random number * random number  

   int MultiplicationGuess = input.nextInt();   //reads the answer of multiplication from user and stores it in MultiplicationGuess

 if (MultiplicationGuess == randomOperand1 * randomOperand2) {  //if the user answer is correct

     System.out.println("Correct!");  //displays correct

     correctAns++;  //adds 1 to the count of correctAns every time the user gives correct answer of multiplication

 }else{  //if user answer is incorrect

       System.out.println("Wrong!");  //displays wrong

       System.out.println("The correct answer is " + randomMul);   }  //displays the correct answer of multiplication

   System.out.print(randomOperand1 + " / " + randomOperand2 + " = ");  //displays random number / random number  

   int DivisionGuess = input.nextInt();   //reads the answer of division from user and stores it in DivisionGuess

   if (DivisionGuess == randomOperand1 / randomOperand2) {  //if the user answer is correct

       System.out.println("Correct!");  //displays correct

       correctAns++;   //adds 1 to the count of correctAns every time the user gives correct answer of division

       }else{  //if user answer is incorrect

           System.out.println("Wrong!");  //displays wrong

           System.out.println("The correct answer is " + randomDiv);     }  //displays the correct answer of division

      System.out.print(randomOperand1 + " % " + randomOperand2 + " = ");  //displays random number % random number  

       int ModGuess = input.nextInt();  //reads the answer of modulo from user and stores it in ModGuess

           if (ModGuess == randomOperand1 % randomOperand2) {  //if the user answer is correct

           System.out.println("Correct!");  //displays correct

           correctAns++;   //adds 1 to the count of correctAns every time the user gives correct answer of modulo

           }else{  //if user answer is incorrect

               System.out.println("Wrong!");  //displays wrong

               System.out.println("The correct answer is " + randomMod);    }  //displays the correct answer of modulo

double percentage = correctAns * 25;   //computes percentage

System.out.println("You got " + correctAns + " correct answers.");   //display number of correct answers given by user

System.out.println("That's " + percentage + "%!");         }  } //displays percentage

Explanation:

The program is well explained in the comments mentioned with each line of code. The screenshot of the output is attached.

You might be interested in
Technologies are having a negative impact on businesses.
Aloiza [94]

Answer: False

Explanation: I think its false because technologie has had a good impact on businesses.

4 0
3 years ago
A variation of pronounce is a. Proclaim c. Produce b. Profound d. Pronunciation Please select the best answer from the choices p
Rashid [163]

The answer, according to my knowledge, is (d) <em>pronunciation.</em>

<em />

<em>- Lee Hae :) Have a great day!</em>

3 0
2 years ago
Which statement best explains the way that similar apps are used in different devices?
monitta

The statement that  best explains the way that similar applications are used in different devices is option b:  Although the systems are different, the apps are still designed to work the same way.

<h3>How does an app work?</h3>

An app is known to be a kind of a software that gives room for a person to be able to carry out some specific tasks.

Note that Applications for desktop or laptop computers are said to be called desktop applications and those apps that are used in mobile devices are known to be called mobile apps.

Hence, The statement that  best explains the way that similar apps are used in different devices is option b:  Although the systems are different, the apps are still designed to work the same way.

Learn more about Software applications from

brainly.com/question/22442533

#SPJ1

6 0
2 years ago
Gary lives in an area that receives high rainfall throughout the year. Which device would be useful to him to maintain his compu
-BARSIC- [3]

The correct answer is B.UPS

A UPS or Uninterruptable Power supply makes sure that you have backup in case there is a power outage in your area. It provides ample time for you to save all files before shut down.

6 0
3 years ago
Read 2 more answers
What type of traffic always goes to all devices in a subnet?
zmey [24]
There are three types of traffic in an IP network:
1. Unicast -  one-to-one traffic (traffic from one sender to one receiver) 
2. Multicast - one to many traffic (one sender and more receivers) 
3.Broadcast -  every device in the network will receive the packet
So, the broadcast traffic <span>always goes to all devices in a subnet. </span>
6 0
3 years ago
Other questions:
  • The operating system of a computer is an example of ________ software. science-forum
    7·1 answer
  • Click _______ to view each individual record of a mail merge document.
    5·2 answers
  • What data discovery process, whereby objects are categorized into predetermined groups, is used in text mining?
    9·1 answer
  • An IP address in the form 197.169.100.1 is called a(n) ________. dotted quad encryption key random number sequential access numb
    7·1 answer
  • What is the positional weigh of the digit 7 in the octal number 7642 ?​
    15·1 answer
  • Task #3 Debugging a Java Program
    14·1 answer
  • Write a Java program that launches 1000 threads. Each thread adds 1 to a variable sum that initially is 0. You need to pass sum
    11·1 answer
  • Which one causes concerns for institutions or businesses when they are collected stores and they aren’t secured properly?
    5·1 answer
  • What is a disadvantage of communicating on social media?
    14·1 answer
  • These are pictorial images displayed on a computer screen​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!