Question: Having problems with debugging Exercise 6-2: In this exercise, youll get more practice working NetBeans debugging capabilities by debugging a version of the Number Guessing

Having problems with debugging Exercise 6-2:

In this exercise, youll get more practice working NetBeans debugging capabilities by debugging a version of the Number Guessing Game that has bugs in it.

Find and fix the compile-time errors

1. Attempt to run the project. This should display an error message that contains links to the errors.

2. Find and fix these errors by clicking on the links to jump to the code for the error. Sometimes the error marker in the left margin may not be on the same line as the actual error.

3. Find and fix any remaining compile-time errors. To do that, you can use the error icons to locate the compile-time errors. Then, you can fix them.

Find and fix the runtime error

4. Run the application to test it. Note that it contains a runtime error. Specifically, the game almost always tells you that your guess is is either too high or too low, no matter which number you pick. For example, even if you chose 0, it might tell you that your guess is too high.

5. Use the NetBeans debugger to find and fix the bug that is causing this problem.

The existing code is:

Main.java:

package murach.games;

import java.util.Scanner;

public class Main {

public static void main(String args[]) {

System.out.println("Welcome to the Number Guessing Game");

System.out.println();

Scanner sc = new Scanner(System.in);

System.out.print("Enter upper limit for guess: ");

int upperLimit = Integer.parseInt(sc.nextLine());

NumberGame game = new NumberGame(upperLimit);

System.out.println();

System.out.print("Enter your guess: ");

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

while (guess != game.getNumber()) {

if (guess < game.getNumber()) {

System.out.println("Your guess is too low. ");

} else if (guess > game.getNumber()) {

System.out.println("Your guess is too high. ");

}

game.incrementGuessCount();

System.out.print("Enter your guess: ");

Integer.parseInt(sc.nextLine());

System.out.println("Correct! ");

System.out.println("You guessed the correct number in " +

game.getGuessCount() + " guesses. ");

System.out.println("Bye!");

}

}

NumberGame.java:

package murach.games;

import java.util.Random;

public class NumberGame {

private iny number;

private int guessCount;

public NumberGame(int upperLimit) {

Random random = new Random();

number = random.nextInt(upperLimit + 1);

guessCount = 1;

}

public int getNumber() {

return number

}

public int getGuessCount() {

return guessCount;

}

public void incrementGuessCount() {

guessCount = guessCount + 1;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!