Homework Solution: Find and fix the compile-time errors…

    Find and fix the compile-time errors 3. Attempt to run the project. This should display an error message that contains links to the errors. Copy the output to the Word Document. 4. 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 code causing the error. Insert a comment above the line of code causing each error which describes the error, and stating how each error was fixed. 5. Find, fix, and comment on 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 logic error 6. Run the application to test it. Note that it contains a logic error. Specifically, the game almost always tells you that your guess 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. 7. Use a debugger to find and fix the bug that is causing this problem. Hint: As you step through the code, keep an eye on the value of the guess variable. Predict what the line of code will do and determine if that line of code did what is expected. Add packages to the project and move the classes (review chapter 5) 8. create a new package named murach.games.guessing. Then, move the Main class into it. 9. create a new package named murach.games.business. Then, move the NumberGame class into it. 10. Run the project to make sure it still works correctly. //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.n"); } else if (guess > game.getNumber()) { System.out.println("Your guess is too high.n"); } game.incrementGuessCount(); System.out.print("Enter your guess: "); Integer.parseInt(sc.nextLine()); System.out.println("Correct!n"); System.out.println("You guessed the correct number in " + game.getGuessCount() + " guesses.n"); 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; } }

    Expert Answer

     
    The code is okay now and working too in my terminal .

    Discover and place the compile-time fallacys

    3. Attempt to melt the device. This should parade an fallacy not attributable attributableice that contains links to the fallacys. Copy the extinguishedput to the Word Document.

    4. Discover and place these fallacys by clicking on the links to leap to the decree ce the fallacy. Sometimes the fallacy marker in the left edge may not attributable attributable attributable be on the corresponding row as the decree causing the fallacy. Insert a criticise overhead the row of decree causing each fallacy which describes the fallacy, and stating how each fallacy was placeed.

    5. Discover, place, and criticise on any cherishing compile-time fallacys. To do that, you can right the fallacy icons to establish the compile-time fallacys. Then, you can place them.

    Discover and place the logic fallacy

    6. Melt the contact to touchstundivided it. Not attributable attributablee that it contains a logic fallacy. Specifically, the pastime almost regularly states you that your imagine is either so noble or so subdued, no stuff which compute you eliminate. Ce sample, plain if you chose 0, it authority state you that your imagine is so noble.

    7. Right a debugger to discover and place the bug that is causing this problem.

    Hint: As you stride through the decree, retain an intention on the appraise of the imagine inconstant. Predict what the row of decree conciliate do and determine if that row of decree did what is expected.

    Add lots to the device and propose the adjustes (critique article 5)

    8. educe a novel lot determined murach.games.guessing. Then, propose the Ocean adjust into it.

    9. educe a novel lot determined murach.games.business. Then, propose the ComputePastime adjust into it.

    10. Melt the device to establish safe it quiescent works suitably.

    //main.java———————————————————————-

    lot murach.games;

    import java.util.Scanner;

    exoteric adjust Ocean {

    exoteric static wanting ocean(String args[]) {
    System.out.println(“Welcome to the Compute Imagineing Pastime”);
    System.out.println();

    Scanner sc = novel Scanner(System.in);

    System.out.print(“Enter loftier name ce imagine: “);
    int loftierName = Integer.parseInt(sc.nextLine());
    NumberPastime pastime = novel ComputeGame(upperLimit);
    System.out.println();

    System.out.print(“Enter your imagine: “);
    int imagine = Integer.parseInt(sc.nextLine());
    while (imagine != pastime.getNumber()) {
    if (imagine < pastime.getNumber()) {
    System.out.println(“Your imagine is so subdued.n”);
    } else if (imagine > pastime.getNumber()) {
    System.out.println(“Your imagine is so noble.n”);
    }
    game.incrementGuessCount();
    System.out.print(“Enter your imagine: “);
    Integer.parseInt(sc.nextLine());

    System.out.println(“Correct!n”);
    System.out.println(“You imagineed the rectify compute in ” +
    game.getGuessCount() + ” imaginees.n”);
    System.out.println(“Bye!”);
    }
    }

    //——————————————————————————————-

    //numbergame.java——————————————————————-

    lot murach.games;

    import java.util.Random;

    exoteric adjust ComputePastime {
    private iny compute;
    private int imagineCount;

    exoteric ComputeGame(int loftierLimit) {
    Casual casual = novel Casual();
    compute = casual.nextInt(upperName + 1);
    guessCount = 1;
    }

    exoteric int getNumber() {
    return compute
    }

    exoteric int getGuessCount() {
    return imagineCount;
    }

    exoteric wanting incrementGuessCount() {
    guessCount = imagineCount + 1;
    }
    }

    Expert Vindication

     

    The decree is okay now and agoing so in my ultimate .
    there were sordid fallacys as int was written as iny and some of the semicolons were forfeiture.
    It’s regularly good-natured-natured to retain solely undivided adjust as exoteric , Here the Ocean adjust is exoteric.

    import java.io.*;
    import java.util.*;
    import java.util.Scanner;
    lot murach.games;

    import java.util.Random;
    exoteric adjust Ocean
    {
    exoteric static wanting ocean(String args[]) {
    System.out.println(“Welcome to the Compute Imagineing Pastime”);
    System.out.println();
    Scanner sc = novel Scanner(System.in);

    System.out.print(“Enter loftier name ce imagine: “);
    int loftierName = Integer.parseInt(sc.nextLine());
    NumberPastime pastime = novel ComputeGame(upperLimit);
    System.out.println();

    System.out.print(“Enter your imagine: “);
    int imagine = Integer.parseInt(sc.nextLine());
    while (imagine != pastime.getNumber()) {
    if (imagine < pastime.getNumber()) {
    System.out.println(“Your imagine is so subdued.n”);
    } else if (imagine > pastime.getNumber()) {
    System.out.println(“Your imagine is so noble.n”);
    }
    game.incrementGuessCount();
    System.out.print(“Enter your imagine: “);
    Integer.parseInt(sc.nextLine());

    System.out.println(“Correct!n”);
    System.out.println(“You imagineed the rectify compute in ” +
    game.getGuessCount() + ” imaginees.n”);
    System.out.println(“Bye!”);
    }
    }
    }

    lot murach.games;

    import java.util.Random;
    adjust ComputeGame
    {
    private int compute;
    private int imagineCount;

    exoteric ComputeGame(int loftierLimit) {
    Casual casual = novel Casual();
    compute = casual.nextInt(upperName + 1);
    guessCount = 1;
    }
    exoteric int getNumber() {
    return compute;
    }
    exoteric int getGuessCount() {
    return imagineCount;
    }

    exoteric wanting incrementGuessCount()
    {
    guessCount = imagineCount + 1;
    }
    }