Question
Preparatory Readings: zyBooks, chapter 1 - 7. Background Information: The Unified Modeling Language (UML) provides a useful notation for designing and developing object-oriented software systems.
Preparatory Readings:
zyBooks, chapter 1 - 7.
Background Information:
The Unified Modeling Language (UML) provides a useful notation for designing and developing object-oriented software systems. One of the basic components of the UML is a class diagram, which are used to depict the attributes and behaviors of a class. A basic class diagram (as shown in the figure below) has three components. The first is the class name. The second component includes the class's attributes or fields. Each attribute is followed by a colon (:) and its data type. The third component includes the class's behaviors or methods. If the method takes parameters, their types are included in parentheses. Each behavior is also followed by a colon (:) and its return type. If the return value of a method is void, the return type can be omitted. For more information on the UML, refer to http://www.uml.org/.
Project Requirements:
1)Develop a simple class that represents a number guessing game. The game is played by the program randomly generating a number and the user attempting to guess that number. After each guess the program will provide a hint to the user identifying the relationship between the number and the guess. If the guess is above the answer then Too High is returned, if the guess is below the answer then Too Low. Also if the difference between the answer and the guess is less than the difference between the answer and the previous guess, Getting warmer is returned. If the difference between the answer and the guess is more than the difference between the answer and the previous guess, then Getting Colder is returned.
GuessingGame |
MAXGUESSESALLOWED : int answer : int generator : Random gameOver : boolean differential : int max : int numGuessesTaken:int |
GuessingGame() GuessingGame (int) newGame(int) guess(int) : String isGameOver() : boolean |
2)The program will allow the user to play multiple games. Once a game is complete the user will be prompted to play a new game or quit.
3)Design and build a GuessingGame class.
a.One constant
i.MAXGUESSESALLOWED
ii.an int that represents the maximum number of guesses the user gets, once this value is passed the game is over. (set to 6)
b.Seven instance variables.
i.answer - an integer representing the randomly generated number.
ii.generator a random Generator object (create from the Java API Random class) (pg 250 in text)
iii.gameOver a Boolean, false if game still in progress, true if the game is over.
iv.differential an integer representing the difference between a guess and the answer.
v.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)
vi.numGuessesTaken an integer that stores the number of guessed taken so far in any game.
c.Constructor and Methods
Default Constructor
Sets max to zero
Creates the random number generator object.
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
1.Generates the answer using the random number generator.(0 - max).
2.Sets gameOver to false.
3.Sets differential to the max value.
4.Sets numGuessTaken to zero.
iv.guess method
1.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:
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 0 and the max number (inclusive) (see sample run below)
d.User has taken too many guess because n
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 method of the class rather than directly accessing the instance fields.
4)Design and build GuessingGameTester class
a.This program will create GuessingGame objects and completely test the GuessingGame Class.
b.The tester will also provide two loops.
c.The first loop will allow the user to play a new game after the previous game is completed.
d.The second or nested loop will prompt the user for a new guess and provide a response based on the guess.
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 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 6 Too low Getting Warmer
Enter your guess, remember it must be between 0 and 100 8 Congratulation
Would you like to play again, enter Y for yes, N for no. y
Welcome to the Guessing Game Enter the maximum number 50 answer is: 36
Enter your guess, remember it must be between 0 and 50 60 Guess out of range, The guess must be between 0 and 50
Enter your guess, remember it must be between 0 and 50 25 Too low Getting Warmer
Enter your guess, remember it must be between 0 and 50 48 Too High Getting Colder
Enter your guess, remember it must be between 0 and 50 37 Too High Getting Warmer
Enter your guess, remember it must be between 0 and 50 36 Congratulation Would you like to play again, enter Y for yes, N for no. n
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