Question
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:
ch08_ex3_GuessingGame - NetBeans IDE 8.2 File Edit View Navigate Source Refactor Run Debug Profile Team Tools Window Help
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started