Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Open the Main class. Modify the loop that prompts the user for a number so that its an infinite while loop. When you do

2. Open the Main class. Modify the loop that prompts the user for a number so that its an infinite while loop. When you do that, you only need to code the two statements that get input from the user at the top of the loop. 3. Modify the if/else statement so it uses a break statement to jump out of the loop if the user guesses the correct number. 4. Run the application to make sure it works correctly. Add some if/else statements 5. Within the loop, modify the if/else statement so the application says, "Way too high!" if the users guess is more than 10 higher than the random number. Otherwise, the application should just say, Your guess is too high. 6. After the loop, add an if/else statement that displays a message that depends on the users number of guesses. For example: Number of guesses Message ================= ======= 3 and 7 What took you so long? Maybe you should take some lessons 7. Run the application to make sure it works correctly. Add a try/catch statement to get a valid integer 8. In the Main class, add a try/catch statement so it catches the NumberFormatException thats thrown by the parseInt method. If this exception is thrown, display a message to the console that says, Invalid number and jump to the top of the loop. This should prompt the user to enter the number again. 9. Run the application to make sure it works correctly. Add an if/else statement to make sure the integer is within a range 10. Add an if/else statement to make sure the user enters a value between the minimum and maximum values. If the user enters a value thats less than or equal to 0, display a user-friendly error message and jump to the top of the loop. Conversely, if the user enters a value thats greater than or equal to the games upper limit, display a user-friendly error message and jump to the top of the loop. 11. Run the application to make sure it works correctly.

Following is the code:

image text in transcribed

image text in transcribed

ch08_ex3_GuessingGame - NetBeans IDE 8.2 File Edit View Navigate Source Refactor Run Debug Profile Team Tools Window Help Projects x -Start Page xEeNain.java x ?? NumberGame.java x ch08_ex3_GuessingGame Source History Source Packages package murach. games; 3import java.util.Scanner; public class Main t murach.games Main.java NumberGame.java Libraries 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); NumberGame game new NumberGame System.out.printin("I have selected a number between 0 and "+ 12 13 14 15 16 17 18 19 20 21 game.getUpperLimit)) 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: "); guess Integer.parseInt(sc.nextLine()); 30 31 32 System.out.println ("Correct!n") System.out.println("You guessed the correct number in" + System.out.println("Bye!"): game.getGuessCount ) +"guesses.In") Output X Type here to search He

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions