Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Guess A Number In this guess a number game, your program will generate a random number between 1 and 1000. The player must then continue

Guess A Number

In this guess a number game, your program will generate a random number between 1 and 1000. The player must then continue to guess numbers until the player guesses the correct number. For every guess, your program will output either "Too high" or "Too low", and then ask for another input. At the end of the game, the number is revealed along with the number of guesses it took to get the correct number. (ie. Keep a count of each guess.)

Needs of Guess A Number:

-Creates a random number to guess

-Keeps track of number of guesses

-Ask user to guess a number

-Let user input a number

-Tells user whether the guess is too high or too low

-Keeps playing until the user guesses the correct number

-Tells user the correct number and the number of tries

-Steps in writing Guess A Number

-First, name the new class, and .java file, GuessANumber_yourinitials.

-Then, create an object of the Random class and call the nextInt() method to generate random number from 1 - 1000. Be careful to generate the correct range - not 0 to 999. Now you have the number that the player has to guess.

-Add an int variable to keep up with the number of guesses, and start it off at 0.

-Add an int variable to hold the user's guess.

-Add a statement to prompt the user to enter a guess between 1 and 1000.

-Now, user Scanner and nextInt() to read the guess.

-User conditionals to let the user know if the guess is too low, too high or CORRECT!

-Update the count on the number of guesses

-loop until correct answer is guessed

-output the correct answer and the number of tries

Bonus:

Use dialog boxes: showInputDialog() and showMessageDialog() to get the input and produce the output of GuessANumber.

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

Database And Expert Systems Applications 15th International Conference Dexa 2004 Zaragoza Spain August 30 September 3 2004 Proceedings Lncs 3180

Authors: Fernando Galindo ,Makoto Takizawa ,Roland Traunmuller

2004th Edition

3540229361, 978-3540229360

More Books

Students also viewed these Databases questions