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
Determine the value of X if (211) base x = (152) base 8, how to do this?
Alex
 we translate the following statement given in terms of logarithms. 211 base x can be expressed into log 211 / log x while 152 base 8 can be expressed int o log 152 over log 8. In this case,
log 211 / log x = log 152 / log 8log x = 0.962x = 10^0.962 = 9.1632
7 0
2 years ago
How can you quickly locate emails with large attachments.
IgorC [24]

To locate emails with large attachments, go to your email and then choose the option of Choose File > Cleanup Tools > Mailbox Cleanup.

Here , one has to Log into their email account and open their inbox and then use the Search Mail bar and type Size to locate or they Set the Find items that are larger than to 9999 and then one has to click Find.

<h3>How do I find emails by attachment size?</h3>

This can also be done for messages that has a size equal to or bigger than 25.

One has to open their message and then they have to right-click on the attachment. You can choose Save As and save to the location of the choice you want.

Learn more about attachments from

brainly.com/question/978078

4 0
2 years ago
Con respecto a la bicicleta y a la escuela, identifique un sistema​
dimulka [17.4K]

Answer:

Cycling, also called bicycling or biking, is the use of bicycles for transport, recreation, exercise or sport.[1] People engaged in cycling are referred to as "cyclists",[2] "bicyclists",[3] or "bikers".[4] Apart from two-wheeled bicycles, "cycling" also includes the riding of unicycles, tricycles, quadricycles, recumbent and similar human-powered vehicles (HPVs).

Cyclists in the 2009 Tro-Bro Léon race.

Police cyclists in London.

A woman cycling in Sri Lanka.

A bike lane in Amsterdam. Bike lanes are dedicated for cyclists and provide shelter from vehicle traffic.

Bicycles were introduced in the 19th century and now number approximately one billion worldwide.[5] They are the principal means of transportation in many parts of the world.

Cycling is widely regarded as an effective and efficient mode of transportation[6][7] optimal for short to moderate distances.

Bicycles provide numerous possible benefits in comparison with motor vehicles, including the sustained physical exercise involved in cycling, easier parking, increased maneuverability, and access to roads, bike paths and rural trails. Cycling also offers a reduced consumption of fossil fuels, less air or noise pollution, reduced greenhouse gas emissions,[8] and greatly reduced traffic congestion.[9] These have a lower financial cost for users as well as for society at large (negligible damage to roads, less road area required). By fitting bicycle racks on the front of buses, transit agencies can significantly increase the areas they can serve.[10]

In addition, cycling provides a variety of health benefits. The World Health Organization (WHO) states that cycling can reduce the risk of cancers, heart disease, and diabetes that are prevalent in sedentary lifestyles.[11][12] Cycling on stationary bikes have also been used as part of rehabilitation for lower limb injuries, particularly after hip surgery.[13] Individuals who cycle regularly have also reported mental health improvements, including less perceived stress and better vitality.[14]

Among the disadvantages of cycling are the requirement of bicycles (excepting tricycles or quadricycles) to be balanced by the rider in order to remain upright, the reduced protection in crashes in comparison to motor vehicles,[15] often longer travel time (except in densely populated areas), vulnerability to weather conditions, difficulty in transporting passengers, and the fact that a basic level of fitness is required for cycling moderate to long distances.

6 0
3 years ago
The __________ backup method is based on the philosophy that a full backup should occur at regular intervals, such as monthly or
kaheart [24]

Answer:

full/incremental backup

Explanation:

I believe it's full/incremental backup.

7 0
2 years ago
What is the maximum value for any octet in an ipv4 ip address?
VladimirAG [237]
They're bytes consisting of 8 bits, so the max value is 2^8-1 = 255
3 0
3 years ago
Other questions:
  • Arrange these stages of website design in the order that they follow. developing planning learning designing testing and deliver
    12·1 answer
  • What are the four primary factors described in the text that set the state for Web 2.0 or the social Web that we enjoy today??
    12·1 answer
  • If johnny has 800 socks and john has 1000 more how much does john have
    9·1 answer
  • "You are on a service call to fix a customer’s printer when she asks you to install a software package. The software is on a per
    13·1 answer
  • Oxnard Casualty wants to ensure that their e-mail server has 99.98 percent reliability. They will use several independent server
    14·1 answer
  • Reading log of any book with page numbers​
    5·1 answer
  • Match these step-by-step directions in the order that you will find them in this course.
    9·1 answer
  • How many comparisons will be done to find 8 in this list using a linear search?
    8·1 answer
  • True or false: all blockchains are programmed to have the same block time (confirmation time) as each other.
    8·1 answer
  • What's the biggest security issue with using social networking sites to market your listings?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!