Assigned: Thursday, September 5
Due: Monday, September 16
40 points
This program tests your understanding of using static methods and println statements. You should write a Java class called Song that should be saved into a file called Song.java. The program should produce as output the following song, which is a shortened version of a classic American folk song named, Bought Me a Cat.
Bought me a cat and the cat pleased me,
I fed my cat under yonder tree.
Cat goes fiddle-i-fee.
Bought me a hen and the hen pleased me,
I fed my hen under yonder tree.
Hen goes chimmy-chuck, chimmy-chuck,
Cat goes fiddle-i-fee.
Bought me a duck and the duck pleased me,
I fed my duck under yonder tree.
Duck goes quack, quack,
Hen goes chimmy-chuck, chimmy-chuck,
Cat goes fiddle-i-fee.
Bought me a goose and the goose pleased me,
I fed my goose under yonder tree.
Goose goes hissy, hissy,
Duck goes quack, quack,
Hen goes chimmy-chuck, chimmy-chuck,
Cat goes fiddle-i-fee.
Bought me a sheep and the sheep pleased me,
I fed my sheep under yonder tree.
Sheep goes baa, baa,
Goose goes hissy, hissy,
Duck goes quack, quack,
Hen goes chimmy-chuck, chimmy-chuck,
Cat goes fiddle-i-fee.
Bought me a pig and the pig pleased me,
I fed my pig under yonder tree.
Pig goes oink, oink,
Sheep goes baa, baa,
Goose goes hissy, hissy,
Duck goes quack, quack,
Hen goes chimmy-chuck, chimmy-chuck,
Cat goes fiddle-i-fee.
The first five verses of the song (all except the final bolded "pig" verse above) must exactly reproduce the output shown above. This includes having identical wording, spelling, spacing, punctuation, and capitalization.
The sixth verse of your song may print any text you like. For example, you could include the "pig" verse. You may include a blank line at the very end of the output if you'd like.
One way to write this program would be to simply write a println statement that outputs each line of the song 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 song and improving the code using static methods.
You should not place any println statements in your main method. (It is okay for main to have empty println statements to print blank lines.) Instead of printing in main, use static methods for two reasons:
You should write static methods to capture the structure of the song. You should, for example, have a method for each of the six verses of the song to print that verse's entire contents.
You should use only one println statement for each distinct non-blank line of the song. 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 song:
Cat goes fiddle-i-fee.
However, a method that prints a single line such as the above is not useful. Instead, you should identify groups of two or more lines that appear in multiple places in the song and create static methods that capture those groups and are called multiple times. There is a general structural redundancy to the song 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. As a point of reference, our solution to this program has twelve static methods other than main (only one of which prints a single line) and occupies 89 lines including comments and blank lines. (This does not mean that your solution is required to be the same length.)
You do NOT have to eliminate redundancy in lines that are similar but not identical, such as these:
Bought me a cat and the cat pleased me
Bought me a dog and the dog pleased me
It is not possible to avoid this partial-line redundancy using just what we have learned so far (static methods and simple println statements), so you are not expected to eliminate it.
Include a comment at the beginning of your program with some basic information and a description of the program. The comments in your program should be written in your own words and not copied from this document. Remember that at a minimum, your comments should include your name and section number, the assignment number, and a very brief description of what the program does.
Though we will cover Chapter 2 while you work on this assignment, please do not use Chapter 2 features such as mathematical expressions for loops, or function with parameters in this program. The goal is to try to capture the structure and eliminate redundancy using functions in exactly the same way we did with the ASCII art examples done in class. (It will not be a common practice to prohibit you from using particular language features, but in this case, the goal of the assignment is to get practice with static methods.)
Please submit your .java file through Canvas. Do not submit your .class file.
It's a good idea to confirm through the Canvas submission page that what you've intended to submit was uploaded. We will grade what you submit. If you submit a corrupted, empty, or otherwise incorrect file, this is what we'll grade. It is your responsibility to verify through the Canvas submission page that you've submitted the correct files and that they were uploaded properly.
Here's a Canvas tutorial on how to submit files.