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
-
When light is incident normally on the interface between two transparent optical media, the intensity of the reflected light is given by the expression In this equation S1 represents the average...
-
Explain the difference between fixed, variable, and semi variable costs.
-
Use a dot plot to display the data, which represent the weights (in kilograms) of 20 polar bears. Organize the data using the indicated type of graph. Describe any patterns. 426 428 436 545 510 386...
-
A small company maintains a petty cash fund for minor expenditures. In June and July 2011, the following transactions took place: a. The fund was established in the amount of $100.00 on June 1 from...
-
A company has a policy "investigate all variances exceeding $3,000 or 15% of the budgeted cost, whichever is lower." There is a variance of $2,000 in repair and maintenance costs of $12,000. What...
-
A company's inventory records report the following in November of the current year: Date Activities Units Acquired at Cost Units Sold at Retail November 1 Beginning inventory 5 units @ $ 4 4 = $ 2 2...
-
Use the information below to answer the questions that follow. U.S. $ EQUIVALENT U.K. pound () 1.5939 Canada dollar (Can$) 1.0091 a. Which would you rather have, $100 or 100? CURRENCY PER U.S. $...
-
How might the SEC's approval of spot-bitcoin ETFs impact mainstream investors' perceptions of cryptocurrency as a legitimate investment option? The article highlights concerns from bitcoin skeptics...
-
Comprehensive comparison between Linux Kernel and windows Kernel? Comprehensive comparison between Linux System and windows System? Comprehensive comparison between Linux Distributions and windows...
-
When looking to invest corporate dollars, what do you think the top-down approach is preferred over the bottom-up approach? Why or why not? In what way might you consider implementing the bottom-up...
-
Ed Colbert is saving for his daughters college education. He estimates he will need $60,000 by the time she goes to school 15 years from now. If Ed can earn 6% annually on his investment, how much...
-
Let G=S, be group of permuatations on n symbols, then which of the following can be True ? There exist a subgroup H of A such that [4 : H] = 2 There exist a subgroup Hof S, such that [S: H]=48 The...
-
What is an insurable interest? Why is it important?
-
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...
-
In a survey, U.S. adults were asked to identify which social media platforms they use. The results are shown in the figure. Six adults who participated in the survey are randomly selected and asked...
-
Rotator cuff surgery has a 90% chance of success. The surgery is performed on three patients. Find the probability of the surgery being successful on exactly two patients.
-
Determine whether each experiment is a binomial experiment. If it is, specify the values of n, p, and q, and list the possible values of the random variable x. If it is not, explain why. 1. A certain...
Study smarter with the SolutionInn App