CMSI 185
Homework #4
Due: 2009-04-07
Readings: Read Chapter 5
of David Eck's text. Make sure you read the entire chapters,
including material such as quizzes, exercises, and solutions
(if any) at the end of each
chapter.
In this homework assignment, you are to implement variations
on a couple of the problems in Chapter 5 of Eck's book, as well as
one class of your own. Eck provides
solutions to each of his problems, accompanied by some nice discussion.
You will use his solutions as a starting point for your own work.
There are a few requirements that apply to every problem, be sure
to follow them:
- Do not use TextIO.java; use standard Java IO, as ugly as it is.
- Use braces for compound statements, even if there is only one subordinate statement.
- Do a better job of spacing than the author.
- Avoid the silly "//end" comments.
- Where possible, initialize variables in their declaration.
- Javadoc comments should start with singular present tense verbs, not commands.
- Don't use abbreviations like str or prevCh or rollCt.
- Don't use capital letters for parameters.
- If there is anything you are unsure about, style-wise, please ask.
Here are the problems:
- (20 pts) Exercise 5.2 in the text, but add
a method to return the mode of the dataset. The
mode is a value that appears most often. For example,
the mode of the set [3 4 7 4 6] is 4. This problem is a little
harder than it looks.
- (60 pts) Modify Exercise 5.3 in the text to compute statistics
for the number of rolls until certain rolls from the game of
Yahtzee come up. You can find details of the game online, but
all you need to do for this assignment is
- Write a variation of the PairOfDice class to hold five dice, not just two.
- Include methods in this class called
- isThreeOfAKind()
- isFourOfAKind()
- isFullHouse()
- isYahtzee()
You are not required to write methods for small straights and large
straights, but you are encouraged to try if you have time.
- (20 pts)Exercise 5.6 in the text, but fix up the
toString() methods to avoid switch statements. Instead, pick
out the values using the substring method from the String class
on the string " A 2 3 4 5 6 7 8 910 J Q K", and do a similar
thing to pick out actual suit characters for Suit objects
(see http://en.wikipedia.org/wiki/Miscellaneous_Symbols).