Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Guessing Game Guess.java The Guess class should provide the method play to actually play the game. Arrange that the method play has no arguments.

The Guessing Game

Guess.java

The Guess class should provide the method play to actually play the game. Arrange that the method play has no arguments.

The game is that the program is to choose a random number in the range 1 to 1000, and then for the player to attempt to guess that number. At each round, the user enters a guess, and is told whether the number is too high, too low, or correct. If not correct, player may try again, until the player guesses the correct number (you may, if you wish, allow the player to resign by entering a zero). Count the number of guesses.

When the player guesses the correct number, display a message, Congratulations, you guessed the number! Following that show one of the three following messages.

  • If the number of guesses was fewer than 10, display, Either you know the secret or you were lucky!
  • If the number of guesses was exactly 10, display, Aha! you know the secret!
  • Otherwise, display, You should be able to do better!

GuessingGame.java

The GuessingGame class should be a simple class (with a main method) that creates any needed instance of the Guess class, sets it up for one game, and calls the play method of the class. When each game ends, the GuessingGame class should ask whether the player wishes to play another game. It should then either cause another game to be played, or terminate.

The other program is a guessing game. The program is to use a random number generator to think of a number, here, between 1 and 1000 inclusive, and the user (the player) then should try to guess the number.

The GuessingGame class should be a simple class (with a main method) that creates any Guess object or objects needed, and each time a game is to be played, calls the play method of the class Guess. When the game is finished, this main class should ask the user whether they want to play another game, and if so, goes back and causes another game to be played

The Guess class should provide the method play to actually play the game. Thus, the Guess class represents one game. This constructor for this class could be written to take no parameters, but you could make it more general by having it take a lower guessing limit, and an upper guessing limit as parameter values. Additionally, since the play method is specified to have no parameters, the constructor will need an additional parameter, passing in a value that informs the Guess class of where to get the input of the user's guesses (a Scanner value would be the most appropriate).

If the Guess class is generalized to have the lower and upper limits as parameters, the number of guesses in the best search will vary according to the number of values that could be the answer.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions