Listing 5.4, SubtractionQuizLoop.java, generates five random subtraction questions. Revise the program to generate ten random addition questions
Question:
Listing 5.4, SubtractionQuizLoop.java, generates five random subtraction questions. Revise the program to generate ten random addition questions for two integers between 1 and 15. Display the correct count and test time.
Listing 5.4
Transcribed Image Text:
1 import java.util.Scanner; 2 3 public class SubtractionQuizLoop { 4 public static void main(String[] args) { final int NUMBER_OF_QUESTIONS = 5; // Number of questions int correctCount = 0; // Count the number of correct answers int count = 0; // Count the number of questions long startTime = System.currentTimeMillis(); String output = " "; // output string is initially empty Scanner input = new Scanner (System.in); 10 11 12 13 while (count < NUMBER_OF_QUESTIONS) { // 1. Generate two random single-digit integers int numberl = (int) (Math.random () * 10); int number2 = (int)(Math.random () * 10); 14 15 16 // 2. If numberl < number2, swap numberl with number2 if (number1 < number2) { int temp = numberl; numberl = number2; number2 - temp; 17 18 19 20 21 22 23 // 3. Prompt the student to answer "What is numberl - number2?" System.out.print( "What is " + numberl + " - " + number2 + "? "); int answer = input.nextInt(); 24 25 26 27 28 // 4. Grade the answer and display the result if (numberl - number2 == answer) { System.out.prfintln("You are correct!"); correctCount+; // Increase the correct answer count 29 30 31 32 33 34 35 else System.out.printIn("Your answer is wrong. \n" + numberl + " - " + number2 + " should be " + (number1 - number2)); 36 37 38 // Increase the question count 39 40 count++; output += "\n" + numberl + "-" + number2 + "=" + answer + ((numberl - number2 == answer) ? " correct" : 41 42 wrong"); 43 44 45 46 long endTime = System.currentTimeMillis(); long testTime = endTime - startTime; 47 System.out.println("Correct count is " + correctCount + "\nTest time is " + testTime / 1000 + " seconds\n" + output); 48 49 50 51 } What is 9 - 2? 7 - Enter You are correct! What is 3 - 0? 3 -Enter You are correct! What is 3 - 2? 1 FEnter You are correct! What is 7 - 4? 4 PEnter Your answer is wrong. 7 - 4 should be 3 What is 7 - 5? 4 - Enter Your answer is wrong. 7 - 5 should be 2 Correct count is 3 Test time is 1021 seconds 9-2=7 correct 3-0=3 correct 3-2-1 correct 7-4=4 wrong 7-5=4 wrong
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (8 reviews)
Output What is 9 8 14 Your answer is wrong 9 8 should be 17 What is 14 4 18 You are correct What is ...View the full answer
Answered By
Utsab mitra
I have the expertise to deliver these subjects to college and higher-level students. The services would involve only solving assignments, homework help, and others.
I have experience in delivering these subjects for the last 6 years on a freelancing basis in different companies around the globe. I am CMA certified and CGMA UK. I have professional experience of 18 years in the industry involved in the manufacturing company and IT implementation experience of over 12 years.
I have delivered this help to students effortlessly, which is essential to give the students a good grade in their studies.
3.50+
2+ Reviews
10+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Listing 3.3, SubtractionQuiz.java, randomly generates a subtraction question. Revise the program to randomly generate an addition question with two integers less than 100. Listing 3.3 1 import...
-
Listing 2.6, ShowCurrentTime.java, gives a program that displays the current time in GMT. Revise the program so that it prompts the user to enter the time zone offset to GMT and displays the time in...
-
Listing 2.7, ShowCurrentTime.java, gives a program that displays the current time in GMT. Revise the program so that it prompts the user to enter the time zone offset to GMT and displays the time in...
-
We can measure how good a center Kevin Bacon is by computing each performer's Hollywood number or average path length. The Hollywood number of Kevin Bacon is the average Bacon number of all the...
-
The conventional algorithm for evaluating a polynomial anxn + an1xn1 + +a1x + a0 at x = c can be expressed in pseudocode by procedure polynomial(c, a0, a1, . . . , an: real numbers) power := 1 y :=...
-
A reaction has H rxn = -255 kJ and S rx n = 211 J/K. Calculate G rxn at 55 C. a) 11.9 10 kJ c) -267 kJ b) 69.5 x 10 kJ d) -324 kJ
-
In the benzene adsorber of Example 9.7, the flow rate is increased to \(0.25 \mathrm{~m}^{3} / \mathrm{s}\). Calculate the breakthrough time and the fraction of the bed adsorption capacity that has...
-
Allison Corporation acquired 90 percent of Bretton on January 1, 2016. Of Bretton's total acquisition- date fair value, $60,000 was allocated to undervalued equipment (with a 10-year remaining life)...
-
Connect each yearly salary to the correct paycheck payment. A. $55,000 B. $60,000 C. $26,000 D. $129,000 E. $56,000 OS $500 weekly $5,000 monthly $2,333 semi-monthly $4,961 biweekly $4,583 monthly
-
A manufacturing plant make wind mill assemblies & can produce 50 units in a month in two period of 15 days each ; following is the data for number of defects arising per month. Month JAN FEB MAR APR...
-
Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting...
-
Write a program that displays the following table (note that 1 kilogram is 2.2 pounds): Kilograms Pounds 1 ....................................... 2.2 3 ...................................... 6.6 ......
-
Write Verilog code for a 4-to-2 binary encoder.
-
1) If the weight of 1 liter of water is defined to be 1 kilogram,how many pounds does 1 cubic feet of water weigh? 2)The carat is a commonly used unit of mass forgemstones. How many carats are there...
-
Part 2: Sustainability Reporting Background: (50 marks) There is an increasing demand and attention to the issue of sustainability reporting around the world. While a group of people support the...
-
What differences distinguish between structured and unstructured databases? What are the three different types of structured customer-related database?
-
What is the purpose proposal? Assume you are a summer intern at a publicly traded company in Canada and you report to Chantal Leadren. Chantal assigns you the following task: "I've been talking to...
-
In what ways can Artificial Intelligence be leveraged to enhance the efficiency and effectiveness of return processes within the realm of supply chain management?
-
Distinguish between the three types of opinions other than unmodified and explain the circumstances in which each is appropriate.
-
How has the too-big-to-fail policy been limited in the FDICIA legislation? How might limiting the too-big-to-fail policy help reduce the risk of a future banking crisis?
-
Write a servlet that stores the following cookies in a browser, and set their max age for two days. Cookie 1: name is color and value is red. Cookie 2: name is radius and value is 5.5. Cookie 3: name...
-
Write a servlet that displays all the cookies on the client. Theclient types the URL of the servlet from the browser to display all the cookies stored on the browser. (see Figure 37.32.)...
-
Create an HTML form that prompts the user to enter a Java program in a text area, as shown in Figure 37.33a. The form invokes a servlet that displays the Java source code in a syntax-highlighted HTML...
-
Solve 1. f(x) = ln(2x-1) 2. f(x)=(x-1) 5x3+x 3. f(x) = e+x = 3 4. f(x) = e 5. f(x)=(3x -2x+1) 6. f(x)=2x-2x+3 7. f(x)= 8. f(x) = 1 2x-1 1 (4x + x)
-
4. Assume that country A's saving level is fixed at SA = 10 and country B's saving level is fixed at SB 25. Except the saving level, these two countries share the same economic parameters. In every...
-
How do advanced query planning strategies such as multi-stage optimization, bushy tree optimization, and join order enumeration address the combinatorial explosion of query plan search space,...
Study smarter with the SolutionInn App