For the first part of this assignment, you will extend the existing PairOfDice class. This class encapsulates two six-sided dice so that they can be rolled together.
getNumSides2, which return the number of sides on the first and seecond dice, respectively.
PairOfDiceobject so that the number of doubles rolled so far is maintained.
percentageOfDoublesthat returns the percentage of rolls so far that were doubles. It should return 0.0 if called before any rolls have taken place.
For the second part of this assignment, you are to design and implement a class
for playing a simple guessing game. When created, a
should randomly select a number between 1 and some (user-specified) maximum, and then allow the
user to try to guess the number. Each time a guess is made, the object should
inform the user whether they are correct, too high, or too low. It should also
be possible to determine the number of guesses made by the user.
For example, suppose a
GuessingGame object picked the number 37. If the user
initially called the
makeGuess method with a guess of 50, then the
method should return the string
"50 is too high. Guess again...".
If he/she then
makeGuess with a guess of 30, then the method should return
"30 is too low. Guess again...". Finally, if he/she calls
makeGuess with the correct guess of 37, then the method should return
"37 is correct!".
The detailed behavior of this class is defined by the GuessingGame.html javadoc page. Your class should meet the specifications in this page, and include comments that would generate a similar page.
One you have your class implemented, you can consider strategies for playing the guessing game. If you make guesses at random, you might get lucky and guess the correct number quickly or it might take a very long time. It turns out that there is an optimal strategy for making guesses that minimizes the worst case. That is, you can guarantee finding the answer in a set number of guesses, and that number is as small as it can be (in terms of a guarantee). The strategy is simply to pick the middle number in the possible range of numbers on each guess. For example, if the range is 1 to 100, then you start by guessing 50. If that is too high, then you know the number is between 1 and 49. Next, pick the middle number in that range, 25. If that is too low, then you know the number is between 26 and 49. Pick the middle number in that range, 37, and so on until the number is guessed.
Answer the following questions using your
GuessingGame.java, and a text document containing your answers to the above questions.