Write a complete program for the user to play a number guessing game. The computer generates a
Question:
Write a complete program for the user to play a number guessing game. The computer generates a random number from 1-10, and the user gets one chance to guess that number. Output a message whether the guessed number was correct. After each game the player will be asked to play another game. When the user decides to stop, the winning percent of games will be displayed. The statement that will generate a random number from 1 to 10 inclusive is:
First, define a class that represents one number guessing game which should include the play method that generates a random number, asks the user for input, checks if the user won, and displays the result. Make sure to keep track of the number of games played and the number of games the user won.
Next, implement a main program to play the number guessing game. Use a loop to play the game multiple times. At the conclusion display statistics of games.
Use an option dialog box like the blow for the user input. Option dialog boxes are discussed in Appendix A.7.
The user will be notified the result in the message dialog boxes that are similar to the ones shown below:
After each game, use a confirmation dialog box discussed in Appendix A. 6 for the user to click on yes or no.
When the user clicks no, output the percent of winning games. Example is shown below:
Step by Step Answer:
Guide To Java A Concise Introduction To Programming
ISBN: 978-3031228414
2nd Edition
Authors: James T. Streib, Takako Soma