2 B 1 5 B Emport java.util.Scanner; import java.util. Random; public class Guess { // You...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
2 B 1 5 B Emport java.util.Scanner; import java.util. Random; public class Guess { // You need to define a method with the following properties: // - The method's name is isGuessCorrect // - The method's return type is String // The method's first parameter is an int, representing the user's guess The method's second parameter is a long, which acts as a seed // // // // "Guess was incorrect. The correct guess was: " + chosen ...where chosen is the number the computer chose. // TODO - write your code below this comment. public static String isGuess Correct(int guess, long seed) { int y = makeRandom IntBetween And2Inclusive (seed); if (guess == y) { return "Guess is correct"; } else { return "Guess was incorrect. The correct guess was: + y; The method must call makeRandom IntBetween And2Inclusive with the given seed. This method determine's what the computer's chosen number is. If the computer's chosen number is equal to the guess, it returns the String "Guess is correct!". Otherwise, it returns the String: } } } // DO NOT MODIFY makeRandom Int Between And2Inclusive! public static int makeRandom Int Between And2Inclusive (long seed) { Random random = new Random (seed); return random.nextInt(3); 1 import static org.junit.Assert.assertEquals; 2 import org.junit. Test; 3 4 public class Guess Test { 5 6 7 8 9 0 _1 2 3 4 5 _6 _7 _8 9 :0 1 2 3 24 25 6 27 8 9 0 51 =2} 33 @Test public void testWithe() { assertEquals("Guess is correct!", Guess.isGuessCorrect(0, 1234561)); } @Test public void testWith1() { assertEquals("Guess was incorrect. The correct guess was: 0", Guess.isGuess Correct(1, 1234561)); } @Test public void testWith2() { assertEquals("Guess was incorrect. The correct guess was: 0", Guess.isGuess Correct (2, 1234561)); } @Test public void testWith1DifferentSeed () { assertEquals("Guess was incorrect. The correct guess was: 2", Guess.isGuess Correct(0, 6543211)); }L @Test public void testWith2DifferentSeed() { assertEquals("Guess is correct!", Guess. isGuess Correct (2, 6543211)); } Step 1: Edit Guess.java Download the Guess.java file, and open it in jGrasp (or a text editor of your choice). This program will ask the user to guess a number between 0 and 2 inclusive, and will report if the user's guess is the same as some number the computer chose. A caveat is that while the computer is choosing a random number, it always chooses when run interactively, as it will always s use the same seed value of 123456. Example output of the program is shown below, with user input shown in bold: Guess a number between 0 and 2, inclusive: 1 Guess was incorrect. The correct guess was: 0 Further example output of the program is shown below, with user input shown in bold: Guess a number between 0 and Guess is correct! inclusive: 0 Step 2: Open Guess Test.java as a Test File Download the Guess Test.java file, being s sure to put it in the same folder/directory as your Guess.java file. This file contains a number of tests for the method you wrote in the previous step. Open this file in jGraspa as a test file, using the same instructions you've used in previous labs. Run the tests in the file. Your code should pass all the tests. If your code does not pass all of the tests, edit your code in Guess.java until you can get all the tests to pass. You do not need to write any of your tests in GuessTest.java. 2 B 1 5 B Emport java.util.Scanner; import java.util. Random; public class Guess { // You need to define a method with the following properties: // - The method's name is isGuessCorrect // - The method's return type is String // The method's first parameter is an int, representing the user's guess The method's second parameter is a long, which acts as a seed // // // // "Guess was incorrect. The correct guess was: " + chosen ...where chosen is the number the computer chose. // TODO - write your code below this comment. public static String isGuess Correct(int guess, long seed) { int y = makeRandom IntBetween And2Inclusive (seed); if (guess == y) { return "Guess is correct"; } else { return "Guess was incorrect. The correct guess was: + y; The method must call makeRandom IntBetween And2Inclusive with the given seed. This method determine's what the computer's chosen number is. If the computer's chosen number is equal to the guess, it returns the String "Guess is correct!". Otherwise, it returns the String: } } } // DO NOT MODIFY makeRandom Int Between And2Inclusive! public static int makeRandom Int Between And2Inclusive (long seed) { Random random = new Random (seed); return random.nextInt(3); 1 import static org.junit.Assert.assertEquals; 2 import org.junit. Test; 3 4 public class Guess Test { 5 6 7 8 9 0 _1 2 3 4 5 _6 _7 _8 9 :0 1 2 3 24 25 6 27 8 9 0 51 =2} 33 @Test public void testWithe() { assertEquals("Guess is correct!", Guess.isGuessCorrect(0, 1234561)); } @Test public void testWith1() { assertEquals("Guess was incorrect. The correct guess was: 0", Guess.isGuess Correct(1, 1234561)); } @Test public void testWith2() { assertEquals("Guess was incorrect. The correct guess was: 0", Guess.isGuess Correct (2, 1234561)); } @Test public void testWith1DifferentSeed () { assertEquals("Guess was incorrect. The correct guess was: 2", Guess.isGuess Correct(0, 6543211)); }L @Test public void testWith2DifferentSeed() { assertEquals("Guess is correct!", Guess. isGuess Correct (2, 6543211)); } Step 1: Edit Guess.java Download the Guess.java file, and open it in jGrasp (or a text editor of your choice). This program will ask the user to guess a number between 0 and 2 inclusive, and will report if the user's guess is the same as some number the computer chose. A caveat is that while the computer is choosing a random number, it always chooses when run interactively, as it will always s use the same seed value of 123456. Example output of the program is shown below, with user input shown in bold: Guess a number between 0 and 2, inclusive: 1 Guess was incorrect. The correct guess was: 0 Further example output of the program is shown below, with user input shown in bold: Guess a number between 0 and Guess is correct! inclusive: 0 Step 2: Open Guess Test.java as a Test File Download the Guess Test.java file, being s sure to put it in the same folder/directory as your Guess.java file. This file contains a number of tests for the method you wrote in the previous step. Open this file in jGraspa as a test file, using the same instructions you've used in previous labs. Run the tests in the file. Your code should pass all the tests. If your code does not pass all of the tests, edit your code in Guess.java until you can get all the tests to pass. You do not need to write any of your tests in GuessTest.java.
Expert Answer:
Answer rating: 100% (QA)
It looks like youre working on a Java program for a guessing game Below is the corrected version of your Guess class with the required method isGuessC... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
Define cognitive psychology and identify key milestones in the development of cognitive psychology as a discipline?
-
4.22 Consider the left-shift operator on l (N), S : l (N) l (N), S(x1, x2,...) := (x2, x3, . . . ). (i) Show that S is a bounded linear operator. (ii) Show that S is not an isometry. (iii) Find the...
-
5. An urn contains five red and three greens balls. The balls are chosen at random, one by one, from the urn. If a red ball is chosen, it is removed. If a green ball is chosen, it is returned to the...
-
Use the test of your choice to determine whether the following series converge. 1 + 1.3 1 3.5 + 1 5.7
-
For the same random sample, when the confidence level c is reduced, the confidence interval for becomes shorter.
-
As part of its commitment to greenhouse gas reduction, the Government of Ontario, Canada, offers incentives to increase the adoption of electric vehicles. For example, new electric vehicles with a...
-
Shiek Shoes sold an administrative building to its parent, Pearl Industries, on January 1, 2015, for \($8,000,000.\) At the time of sale, the building was carried on Shiek's books at original cost of...
-
Hearty Soup Co. uses a process cost system to record the costs of processing soup, which requires the cooking and filling processes. Materials are entered from the cooking process at the beginning of...
-
2 points - Little Oil has outstanding 1 million shares with a total market value of $38 million. The firm is expected to pay $1.00 million of dividends next year, and thereafter, the amount paid out...
-
On March 10, 2006, Nortel Networks Corp. announced that it would delay filing its 2005 financial reports with the SEC. The delay arose because Nortel and its auditors decided that certain revenue...
-
Anna and Ben have to split a cake. The cake consists of 6 pieces. Anna and Ben take turns in making offers, Anna starts. (The offers can be any real numbers.) After each rejected offer ants however...
-
I loan an amount of 380,000 php on MITCC ( Mapua Institute of Technology Credit Cooperative.) payable in four years semi-monthly salary deduction @ 10 % interest.What is my deduction every payday?
-
The cost of goods manufactured in a factory is Rs 200,000, opening finished goods cost is Rs 50,000, closing finished goods are Rs 100,000, and ending Work In Process is Rs 10,000. What is the Cost...
-
Identify the organisation's standards and values, whether stated or implied by the way the organisation conducts its business Use organisation's standards and values in conducting business Evaluate...
-
Hello! Can I get some help in this problem? Thanks The inventory stock card of Beth Corporation on January 2021 is as follows: Purchase Price Purchase Units Sold Units Balance Jan 01 P110 10,000...
-
Where have you noticed data analytics in your own social media use? What improvements have been made due to the applications' ability to respond to your personal data? With data collection, privacy...
-
K O Points: 0 of 1 Save Andrew Industries is contemplating issuing a 30-year bond with a coupon rate of 7.12% (annual coupon payments) and a face value of $1,000. Andrew Industries believes it can...
-
Air pollution generated by a steel mill is an example of a) a positive production externality. b) a negative production externality. c) a public good. d) the free-rider problem. State and local taxes...
-
Write a program that promptsthe user to enter the number of students and each students name and score, and finally displays the name of the student with the highest score.
-
Write a program for the Knight?s Tour problem. Your program should let the user move a knight to any starting square and click the Solve button to animate a knight moving along the path, as shown in...
-
Write a program that prompts the user to enter a directory name and creates a directory using the Files mkdirs method. The program displays the message Directory created successfully if a directory...
-
Joyce Lee earns $30,000 a year. Her employer pays a matching Social Security tax of 6.2% on the first $94,200 in earnings, a Medicare tax of 1.45% on gross earnings, and a FUTA tax of 0.8% and a SUTA...
-
The Form 941 tax deposit includes which of the following types of taxes withheld from the employee and paid by the employer? (a) Federal income tax and FUTA tax (b) Federal income tax and Social...
-
The W-4, which shows total annual earnings and deductions for federal and state income taxes, must be completed by the employer and given to the employee by January 31. True/False
Study smarter with the SolutionInn App