Question: ADVANCED OBJECT-ORIENTED PROGRAMMING Programming Assignment: DESIGNING JAVA CLASSES Introduction - This exercise is meant to introduce you to designing your own Java classes (including constructors
ADVANCED OBJECT-ORIENTED PROGRAMMING
Programming Assignment: DESIGNING JAVA CLASSES
Introduction -
This exercise is meant to introduce you to designing your own Java classes (including constructors and methods). You will be implementing:
A couple of simple guessing game classes (GuessLogic and GuessList) that generates a random number between 1 and some limit, and keeps track of whether the player has correctly guessed it, what numbers they have previously guessed, and how many guesses they have made.
A couple of very simple main command line applications (EasyGame and HardGame) that run guessing games (with slightly different rules) for, using those support classes.
Here is a simple UML diagram that gives the relationships between the classes:

In addition, you will be producing a simple design document in advance of the final implementation, listing the methods your GuessLogic and GuessList support classes will implement.
The SimpleGame Application - This game repeatedly prompts the player for a number between 1 and 10 until they correctly guess it.
- The only feedback for incorrect guesses is that it is not correct.
- When they guess the number, they are told how many tries it took.
- They have an unlimited number of tries in this game.
- If they guess a number that has already been guessed, they are warned and the previous guesses are all printed out. These guesses do not count against the number of tries.
For example:

The HardGame Application - This game repeatedly prompts the player for a number between 1 and 100.
If the guess is incorrect. the player is told whether the guess is too high or too low. They have a limit of 7 guesses. If they make 7 incorrect guesses, the player loses and the game is over. They are not told whether a guess has already been made, and previously made guesses count against the number of tries. If they lose, the correct number and the guesses they made are printed out.
For example:


The GuessLogic Class -
You are to implement a simple support class that controls the logic of the guessing game (stored in the file GuessLogic.java).
Note that I am not specifying the methods and constructors for that class (except for the toString method below). These are the main design decisions for this assignment! However, I do have the following requirements:
Separating the Logic and the User Interface -
All of the logic for the game must be handled within GuessLogic class. In other words, the application classes are not to keep track of the correct answer, the number of guesses made, the number of guesses remaining, or the numbers previously guessed. On the other hand, the application classes are responsible for all of the I/O. In other words, the GuessLogic class is not to print anything (except possibly for the purposes of debugging). Neither is it to return any messages to be printed by the application methods in the GuessLogic class should only return numeric or Boolean values (as a justification, your company plans to market the applications in other languages).
One thing to think about is how some GuessLogic method can return whether a guess is too high, too low, or correct without returning a string. A better way of doing this is to define a static constant for each in the GuessLogic class for each, and return that instead. For example, you might define LOW = -1 in GuessLogic class, and compare the returned value to GuessLogic.LOW.
Suggestions - I do suggest that you think about providing GuessLogic methods for the following:
(1) Allowing the user to guess a given number.
(2) Finding whether the number has been guessed.
(3) Finding the numbers that have already been guessed.
(4) Finding the number of guesses made.
(5) Finding whether the player has any guesses left.
You should also have the GuessLogic constructor generate the correct answer. Generating random numbers can be done with the nextInt method in the Random class (in java.util). See the Java API for details.
The GuessList Class -
You are to implement a separate support class to keep track of the numbers already guessed. This class will be used by GuessLogic , which will construct and store an instance of that class. There are a number of ways to do this, including:
i. Keeping an array of int, & adding each new guess to the end of that array (like the Roster class does for names).
ii. Keeping an array of boolean, each corresponding to a possible number. Initially each is false & is then set to true when that number is guessed.
I suggest that you think about providing GuessList methods for the following:
i. Finding whether the number has been guessed.
ii. Finding the numbers that have already been guessed.
Encapsulation - As mentioned in class, your representation must be properly encapsulated. That means all member variables must be private.
Documentation - As with any program, your source code should be well documented! For this assignment, this includes the following:
For the GuessLogic and GuessList classes, make sure that you put a header at the top of each method and constructor that briefly explains what it does (particularly in terms of the member variables).
For the applications, make sure that you explain how they work, particularly in terms of manipulating the GuessLogic object.
Note that this documentation is to be in JavaDoc format. That is, I should be able to run your classes through the JavaDoc tool and see your documentation as an API.
The Design Document -
The initial stage of most object-oriented projects is the creation of a design document that lets developers of a class and its users agree on the methods and constructors the classes will provide. This will be the first stage of this assignment. It is worth 10 of the possible 50 overall points of the assignment.
Specifically, you will turn in a document describing each constructor and method your GuessLogic and GuessList support classes will provide. To keep things simple, these descriptions will be similar to the JavaDoc documentation you will turn in later (in fact, if you do the design correctly you can just reuse it in your final documentation).
Include the following for each method:
(1) An abstract description of what it does.
(2) What each input parameter represents.
SimpleGame GuessLogic |- GuessList HardGame
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
