Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am working on Debugging code for the number guessing game. I have already fixe

ID: 3902520 • Letter: I

Question

I am working on Debugging code for the number guessing game. I have already fixed all the other issues except for the issue that keeps outputting either too high or too low, regardless of the number. If the number is 5 and I enter 1, it will say too low, but if I enter 9 next it will still say too low, and vice versa for too high. Following is the code:

ch06 ex2_GuessingGame - NetBeans IDE 8.2 File Edit View Navigate Source Refactor Run Debug Profile Team Tools Window Help | Projects Debu... X Start Page Main.java NumberGame.java x ??'Attach Listener' inalizersusper "main' suspende D> Reference Hand D package murach.games: 3import java.util.Scanner; public class Main t ?? Signal Dispatche D public static void main (String args [) System.out.println("Welcome to the Number Guessing Game") System.out.println ) 10 Scanner sc- new Scanner (System. in); 12 13 14 15 16 17 18 19 20 21 System.out.print ("Enter upper 1imit for guess:") int upperLimit Integer.parseInt (sc.nextLine)); NumberGame game new NumberGame (upperLimit) System.out.println ) System.out.print ("Enter your guess: "); int guessInteger.parseInt (sc.nextLine O) while (guess != game. getNumber ( ) ) { if (guess game.getNumber )) System.out.println ("Your guess is too high.In") 26 27 28 game.incrementGuessCount ) System.out.print ("Enter your guess: "); Integer.parseInt (sc.nextLine )) 30 31 32 System.out.println ("Correct!n") System.out.println("You guessed the correct number in" + game.getGuessCount ) +"guesses.In") System.out.println("Bye!"):

Explanation / Answer

In line no 28 you are reading next guess from the user, but you are not assigning that value to any number thats why this is happening while reading input assign that to guess.like

guess=Integer.parseInt(sc.nextLine());;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote