Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming: Please help with the following assignment. Thank you. uiesiin gGame answer : int generator: Random ameOver: boolean differential: int max : int maxGuessesAllowed

Java Programming: Please help with the following assignment. Thank you.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

uiesiin gGame answer : int generator: Random ameOver: boolean differential: int max : int maxGuessesAllowed : int numGuessesTaken:int Guesisin gGame GuessingGame (int) newGame(int) guess(int): String isGameOver): boolean Design and build a GuessingGame class. a. Seven instance variables. i. answer - an integer representing the randomly generated number. ii. generator - a random Generator object (created from the Java AP.I Random class)(zyBooks Section 2.14) gameOver - a Boolean, false if game still in progress, true if the game is over. differential - an integer representing the difference between a guess and the answer. max - maximum value of the number to guess. For example, if the maximum number is 100 then the number to guess would be between 0 and 100. (inclusive) maxGuessesAllowed - the maximum number of guesses the user gets, once this value is passed the game is over. numGuessesTaken- an integer that stores the number of guessed taken so far in any game. iii. iv. v. vi. vii. Constructor and Methods i. Default Constructor . Sets max to zero 2. Creates the random number generator object. ii. Parameterized Constructor 1. Takes an integer parameter representing the maximum value of the number to guess. 2. Creates the random number generator object. iii. newGame method I. 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. 2. Generates the answer using the random number generator. (0 max 3. Sets gameOver to false. 4. Sets differential to the max value, 5. Sets numGuessTaken to zero, iv. guess method I. Takes in an integer as a parameter representing a new guess 2. Compares the new guess with the answer and generates and returns a String representing an appropriate response. 3. The response is based on: The relation of the guess and answer (too high, too low or correct) a. b. The comparison of difference between the current guess and the answer and the previous guess and the answer. (warmer, colder) Guess out of range error, if the guess is not between 0 and the max number (inclusive) (see sample run below) c. 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. 1. true if game is over 2. 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. Sample Output: Welcome to the Guessing Game Enter the maximum number 100 answer is: 8 (Included for testing only, should not be display in final program) Enter the number of guess allowed Enter your guess, remember it must be between 0 and 100 50 Too High Getting Warmer Enter your guess, remember it must be between 0 and 100 25 Too High Getting Warmer Enter your guess, remember it must be between 0 and 100 12 Too High Getting Warmer Enter your guess, remember it must be between 0 and 100 Too low Getting Warmer Enter your guess, remember it must be between 0 and 100 Congratulation Would you like to play again, enter Y for yes, N for no

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 Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

Students also viewed these Databases questions

Question

Describe the frame layouts for SDLC, Ethernet and PPP.

Answered: 1 week ago