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
-
A marble of mass m and radius r rolls along the looped rough track of Fig. 8-58. What is the minimum value of the vertical height h that the marble must drop if it is to reach the highest point of...
-
Suppose you have been assigned an important position in Foreign Office where meeting people from different backgrounds and culture is normal practice. How would you transform your communication...
-
Consider the regression models described in Example 8.4. Example 8.4 a. Graph the response function associated with Eq. (8.10). Equation (8.10) b. Graph the response function associated with Eq....
-
Shervonne Thomas is the controller at a large manufacturing company located in Chestereld, Virginia. The company has several divisions that evaluate their performance using a return on investment...
-
a) Figure la shows an overall two-port network consisting of Network A and Network B in a certain interconnection. Network A and Network B are respectively a T-network and a -network as shown....
-
The legs of a picnic table form an isosceles triangle as indicated in the figure. If mABC = 80, determine mx and my so that the top of the table will be parallel to the ground. , 80
-
Kenny Young has started his own business, Home and Away Inspections. He inspects property for buyers and sellers of real estate. Young rents office space and has a part- time assistant to answer the...
-
Finding that the next baby born in Alaska is a girl. For Exercises 1118, use the theoretical method to determine the probability of the given outcome or event. State any assumptions that you need to...
-
Considering the application described in the preceding exercise, what changes would you make to the user interface screens to bring them into compliance with the human engineering guidelines...
-
At the Large Hadron Collider in Switzerland, two highenergy protons collide to create new particles. Prior to collision, each proton is accelerated to an energy of \(7000 \mathrm{GeV}\) in the Earth...
-
A uniform 200-kg cube that has a volume of \(8.00 \mathrm{~m}^{3}\) (measured when the cube is at rest in the Earth reference frame) travels perpendicular to a pair of its faces at \(0.672 c_{0}\)...
-
Assume that \($s0\) is initialized to 11 and \($s1\) is initialized to 22. Suppose you executed the code below on a version of the pipeline that does not handle data hazards (i.e., the programmer is...
-
SWOT analysis on spotify, structural framework perspective.
-
How can a promoter avoid personal liability for pre-incorporation contracts?
-
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...
-
2019. Peabody Energy Company and Arch Resources, Inc., are two titans in a now-dwindling industry. Peabody operates three mines in the Southern Powder River Basin (SPRB) in Wyoming, one of which is...
-
Beginning around 1915, Natural Products Refining Corporation (NPRC) operated a chemical plant in Jersey City, New Jersey, at which it turned chromite ore into chromium chemicals (primarily sodium...
-
When GTE Sylvania discovered it was losing market share to other television manufacturers, it developed a franchise plan that limited the number of retailers selling its product in each area....
Study smarter with the SolutionInn App