Answered step by step
Verified Expert Solution
Question
1 Approved Answer
vi . maxGuessesAllowed the maximum number of guesses the user gets, once this value is passed the game is over. vii. numGuessesTaken an integer that
vi maxGuessesAllowed the maximum number of guesses the user gets,
once this value is passed the game is over.
vii. numGuessesTaken an integer that stores the number of guessed
taken so far in any game.
b Constructor and Methods
i Default Constructor
Sets max to zero
Creates the random number generator object.
ii Parameterized Constructor
Takes an integer parameter representing the maximum value of
the number to guess.
Creates the random number generator object.
iii. newGame method
Takes in an integer as a parameter representing the maximum
number of guesses and sets maxGuessesAllowed In other
words, the parameter represents how many guesses the user
gets before the game is over.
Generates the answer using the random number generator.
max
Sets gameOver to false.
Sets differential to the max value.
Sets numGuessTaken to zero.
iv guess method
Takes in an integer as a parameter representing a new guess.
Compares the new guess with the answer and generates and
returns a String representing an appropriate response.
The response is based on:
a The relation of the guess and answer too high, too low
or correct
b The comparison of difference between the current
guess and the answer and the previous guess and the
answer. warmer colder
c Guess out of range error, if the guess is not between
and the max number inclusivesee sample run below
d User has taken too many guess because
numGuessesTaken is greater than maxGuessesAllowed.
If this is the case set isGameOver to true.
v isGameOver method returns the state of game.
true if game is over
false if still in progress.
vi Accessor and mutator methods for all instance fields except the
Random number generator. Use the Accessor or mutator methods
within the other methods of the class rather than directly accessing the
instance fields. For example, use mutator methods in the
parameterized constructor to modify instance variables.
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