Listing 3.3, SubtractionQuiz.java, randomly generates a subtraction question. Revise the program to randomly generate an addition question
Question:
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
Transcribed Image Text:
1 import java.util.Scanner; 3 public class SubtractionQuiz { 4. public static void main(String[] args) { 5 // 1. Generate two random single-digit integers int numberl - (int)(Math.random() * 10); int number2 - (int) (Math.random() * 10); // 2. If number1 < number2, swap numberl with number2 if (numberl < number2) { int temp = number1; 10 11 12 13 numberl - number2; number2 - temp; 14 15 16 // 3. Prompt the student to answer "What is numberl - number2?" System.out.print ("What is " + numberl + Scanner input = new Scanner(System.in); int answer - input.nextInt(); 17 + number2 + "? "); 18 19 20 21 22 23 24 25 // 4. Grade the answer and display the result if (numberl - number2 == answer) System.out.println("You are correct!"); else { System.out.print1n("Your answer is wrong."); System.out.println(number1 + " - " + number2 + " should be " + (number1 - number2)); 26 27 28 29 30 31 } What is 6 - 6? 0 Jbter You are correct! What is 9 - 2? 5 Jover Your answer is wrong 9 - 2 is 7 numberl number2 line# temp output answer 6. 11 12 2. 13 20 Your answer is wrong 9 - 2 should be 7 26
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 57% (7 reviews)
Program plan Declare two variables named number1 and number2 Generate two random numbers The two num...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
-
Write a program that randomly generates an array of 100,000 integers and a key. Estimate the execution time of invoking the linearSearch method in Listing 7.6. Sort the array and estimate the...
-
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...
-
Programming Exercise 3.17 gives a program that plays the scissor-rock-paper game. Revise the program to let the user continuously play until either the user or the computer wins more than two times...
-
Given: Pre-tensioned cables AB and AD, having tensions of 27 and T, respectively, are attached to end A of the L-shaped bracket and exert forces of FAB and FA AD; respectively, on the bracket due to...
-
Convert from radians to degrees: (a) 1 (b) /3 (c) 5/12 (d) - 3/4
-
For a write-through, write-allocate cache, what are the minimum read and write bandwidths (measured by byte per cycle) needed to achieve a CPI of 2? Consider the following program and cache...
-
What is the internal rate of return of the following cash flow diagram? a. 20 percent b. 18.2 percent c. 17.5 percent d. 15 percent $30 $31 0 1 2 3 $30 $15
-
Phillips Company is a manufacturer of computers. Its controller resigned in October 2012. An inexperienced assistant accountant has prepared the following income statement for the month of October...
-
Find the two unknown sides in this triangle. Keep 4 significant digits. x+3.10m -240m-x 5.21m
-
Tommy (age 47) and his wife, Michelle (age 49), live in Columbus, Ohio, where Tommy works for Callahan Auto Parts (CAP) as the vice-president of the brakes division.Tommys 2018 salary is $360,000.CAP...
-
An ISBN-10 (International Standard Book Number) consists of 10 digits: d 1 d 2 d 3 d 4 d 5 d 6 d 7 d 8 d 9 d 10 . The last digit, d 10 , is a checksum, which is calculated from the other nine digits...
-
Write a program that prompts the user to enter the month and year and displays the number of days in the month. For example, if the user entered month 2 and year 2012, the program should display that...
-
Let and Express the following as rational functions. f(x) = X x-2' g(x)= 5-x 5 + x'
-
Find eigenvectors for this matrix M : 0.5 0.2 M = 0.3 0.6 0.1 0.5 0.2 0.2 0.4/
-
Differentiate the function after first rewriting the function in a different form. (Do not use the product or quotient rules.) 5Vx+5x 8x y' = || y= x
-
Explain how programmed I/O is different from interrupt driven I/O. What is polling?
-
Despite having secured good grades in FINN 100 and FINN 200, your mother, who happens to be a doctor at National Hospital, still does not trust you on financial matters. You recommend her to seek...
-
What is the function of the kernel of an operating software?
-
Eng Corporation, a private corporation reporting under ASPE, had the following transactions: Instructions Complete the above table for each of the following requirements. The first one has been done...
-
MgO prevents premature evaporation of Al in a furnace by maintaining the aluminum as Al2O3. Another type of matrix modifier prevents loss of signal from the atom X that readily forms the molecular...
-
Listing 6.8 implements the hex2Dec(String hexString) method, which converts a hex string into a decimal number. Implement the hex2Dec method to throw a NumberFormatException if the string is not a...
-
A university posts its employees salaries at http:// liveexample.pearsoncmg.com/data/Salary.txt. Each line in the file consists of a faculty members first name, last name, rank, and salary (see...
-
Rewrite the Course class in Listing 10.6 to add a clone method to perform a deep copy on the students field. Listing 10.6 - Course.java public class Course i private String courseNane: private string...
-
I. Analyze the geometric construction of the systems shown as in figures. A Figure 1-1 E Figure 1-2 Figure 1-3 bisg ela ad bloode vuilidizel Figure 1-4
-
structural engineering course, i need it asap please. thanks A. Calculate the reactions of the two-span frame shown in figure Figure 4-1 2.5kN/m (a) D E F A B 2m 2m 4m 0 4m B. Calculate member-end...
-
As a hired structural engineering consultant, you were requested to evaluate a four-story building that is damaged by a Magnitude 6 earthquake. The client has no background in any civil/structural...
Study smarter with the SolutionInn App