CIS 1068 - Homework 2
Handed out: 1/26/10
Due: by 10pm on 2/1/10
The task is to write a Java class that prints out a nursery rhyme, as described
below. Your program will be graded on whether or not it prints out the correct
output and on whether the program has a good structure.
Program Description
You will write a Java class called ThisHouse that must be saved into a file called
ThisHouse.java.
Your program should produce the following nursery rhyme as output:
This is the house that Jack built.
This is the malt
That lay in the house that Jack built.
This is the rat
That ate the malt
That lay in the house that Jack built.
This is the cat
That killed the rat
That ate the malt
That lay in the house that Jack built.
This is the dog
That worried the cat
That killed the rat
That ate the malt
That lay in the house that Jack built.
This is the cow with the crumpled horn
That tossed the dog
That worried the cat
That killed the rat
That ate the malt
That lay in the house that Jack built.
This is the maiden all forlorn
That milked the cow with the crumpled horn
That tossed the dog
That worried the cat
That killed the rat
That ate the malt
That lay in the house that Jack built.
You should exactly reproduce the format of this output. This includes having identical
wording, spelling, spacing, punctuation, and capitalization. Please do not include any extra
verses. You may include blank lines at the end of the output, if you like. You do not need to
reproduce the lines surrounding the text, only the text itself.
Stylistic Guidelines
One way to write this program would be to simply write a println statement that outputs each
line of the rhyme in order. However, such a solution would not receive full credit.
Part of the challenge of this assignment lies in recognizing the structure and redundancy
of the rhyme and improving the code using static methods.
Any println statement in your program should not be in your main method. Instead, use
static methods in this program, for two reasons:
- To capture the structure of the rhyme's seven verses. You should be using static methods
to capture the structure of the rhyme. You should, for example, have a method for each of
the seven verses of the rhyme to print that verse's entire contents. You can write additional
methods as you see fit.
- To avoid redundancy. You should use only one println statement for each distinct non-
blank line of the rhyme. For example, the following line appears several times in the
output, but you should have only one println statement in your program that prints that
line of the rhyme:
That lay in the house that Jack built.
There is a general structural redundancy to the rhyme that you should eliminate with your
static methods. Recall that methods can call other methods if necessary. The key question to
ask yourself is whether or not you have repeated lines of code that could be eliminated if you structured your static methods differently.