Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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.
Step by Step Solution
★★★★★
3.36 Rating (152 Votes )
There are 3 Steps involved in it
Step: 1
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...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started