If I run this code, I get two errors. How do I fix theseerrors?
1 import java.util.Random; 2 import java.util.Scanner; 4 5 public class GuessingGamet * This method prompts the user for a guess. It will only prompt the user ones. 8 9 10 The argument provided is the number the user is supposed to guess sp> * If the user enters a number too high (higher than numberToGuess) then print ‘Too high’.If * the user enters a number too low (Lower than numberToGuess) then print ‘Too low’ If the *user guesses the number, then print ‘You guessed it’. 12 13 14 15 16 17 18 19 20 21 sps * The number to guess is assumed to be a number between 1 and 20 (but this method doesn’t check * if number ToGuess provided is indeed between 1 and 20). If the user enters a number that is x not between 1 and 20 (it is less than 1 or greater than 20) then the message to the user k will be Guess is not valid’ and no other message is printed * @param numberToGuess this is the number the user is required to guess * @return true if the guess is correct and equal to numberToGuess and false otherwise. 23 public static boolean getAndCheckGuess(int numberToGuess) 24 25 26 27 28 29 30 31 32 Scanner keyboard = new Scanner(System.in); System.out.print(“Enter your guess) int guess guess keyboard.nextInt(); if(guess>numberToGuess) 34 35 36 37 38 39 40 System.out.println(“Too high”); else if(guess 20) System.out.println( “Guess is not valid”) else if(guess numbe rToGuess) 42 43 System.out.println(“You guessed it”) return true; return false; 46 47 48 /ko* When running this program, it will call getAndCheckGuess with a random number to guess If you want to test with a particular number to guess, provide the number to guess as an argument to this program. For example, if you want the numberToGuess to be 17, * run this program as: java GuessingGame 17 50 52 53 54 xps * This program will call getAndCheckGuess and then print the value returned by that k method/function. * @param args the command line argument provided. If one is provided it is assumed to be the 56 57 58 59 60 61 62 63 64 65 number to guess in the game k/ public static void main(String args)f int numToGuess0 if (args.length 1) Random rand – new Random) nextInt will return a number between and 20 (exclusive 20). Adding 1 results in /a number between 1 and 20 (inclusive) numToGuess-rand.nextInt(20) 1; else /get the number provided as a command line argument and use it as the number to Iguess for the game. numToGuess Integer.parseInt (args ) 67 68 69 70 71 72 73 74 75 76 boolean correct getAndCheckGuess (numToGuess); System.out.println(correct) 1) test_InvalidGuess0(GuessingGameTest) org.junit.ComparisonFailure: Testing message. The number to guess was 11 and gue ss provided was 0. expected : but was:〈[Too low]> 2) test InvalidGuess21(GuessingGameTest) org.junit.ComparisonFailure: Testing message. The number to guess was 20 and gue ss provided was 21. expected: but was: Show transcribed image text
The post Run Code Get Two Errors Fix Errors Q34401438 appeared first on Nurses Den.