CMSI 185
Homework #3
Due: 2009-03-05
Readings: Read Chapter 4
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 each of the problems in Chapter 4 of Eck's book. Eck provides
solutions to each of the 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:
- (15 pts) Exercise 4.1 in the text, but instead of
a printCapitalized method which returns nothing, use a method
which returns a new string which is the capitalized version
of the parameter.
- (15 pts) Exercise 4.2 in the text, but implement a better
hexValue method. Instead of a switch statement, use the
string "0123456789ABCDEF" with charAt and
toUpperCase methods to make the entire method
body only one line long.
- (15 pts) Exercise 4.3 in the text, but
use a Random object, not the Math.random() method.
- (20 pts) Exercise 4.4 in the text, but
take the number of experiments as a command line argument.
- (20 pts) Exercise 4.5 in the text, but
use an enum for the direction, and brighten the mosaic
with shades of cyan, rather than red.
- (15 pts) Exercise 4.6 in the text, but produce
circles instead of squares.