CS 305j - Programming Assignment 2
Problem Decomposition
This is an individual assignment -
you cannot work with anyone else. All work must be done on your own.
Ask the instructional staff for help.
Goals:
- Learn to remove redundancy from your programs through the use of
static methods.
- Practice using the programming conventions that we have discussed
in class.
Write a Java program that produces as output the
words of "The Twelve Days of Christmas", as seen here.
Your program, when executed, must produce all verses (not just the
three you see below), with a single blank line between one verse and
the next.
On the first day of Christmas,
My true love sent to me
A partridge in a pear tree.
On the second day of Christmas,
my true love sent to me
Two turtle-doves and
A partridge in a pear tree.
...
On the twelfth day of Christmas,
My true love sent to me
Twelve drummers drummings,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings.
Four calling birds,
Three French hens,
Two turtle-doves and
A partridge in a pear tree.
You must exactly
reproduce the format of this output, and the wording from the indicated
webpage.
You must use static methods to avoid simple redundancy. You must use
only one println statement for each distinct line of the song. For
example, the line:
A partridge in a pear tree.
appears many times in the output. You may only have one println
statement in your program that displays this line. You may have static
methods in your program that only contain a single println.
You must use a separate static method for each verse of the song.
You are also required to use
static methods to reduce structural redundancy. For example, verse six
and verse seven are very similar/redundant. If you have code segments -
several lines of code - that appear multiple times in your program,
these repeated segments should be eliminated by structuring your static
methods differently.
You are not allowed to use any more
advanced Java features for this assignment. Only Java features that we
have covered in chapter 1 of the textbook are allowed in project 2.
The header for your file (for this project and subsequent projects)
should look like this, with the required information filled in.
/**
* author: <Your Name Here>
* date: <Submission Date>
* CS 305j Assignment 2
* On my honor, <Your Name>, this programming assignment is
my own work.
*
* EID: <Your EID>
* Section: <Unique Number>, <Tuesday discussion time>
*
* <Brief Description - what does the program do?>
*
* Slip Days I am using on this project: <Your Slip Days>
* Slip Days I have used this semester: <Your Total, including for
this project>
*/
public class Song {
<Your program code here>
}
Submit your program in a file called Song.java via the turnin program
by the due date at 11 pm.
Did you remember to:
- review the assignment requirements?
- work on this assignment individually?
- check for compile errors and runtime errors in your program?
- turn in your Java source code, your file Song.java to your cs
305j folder via the turnin program?
- submit your program by the due date at
11 pm?