|
|
|
 |
 |
 |
|
Twelve Days of Christmas
|
|
|  |
by Debbie Carter Lancaster Country Day School Lancaster, Pennsylvania
 |
|
|  |
and Stacy Puckett Providence High School San Antonio, Texas
 |
|
|  |
More Nifty Assignments...
Assignment
Write a program to print all the verses of the "Twelve Days of Christmas" (or some other holiday song of your choosing). I've used the traditional wording in my examples, but you may rewrite the lyrics, as long as the content is appropriate for an academic setting.
As a reminder, here are the first three verses of the traditional version of the song:
On the first day of Christmas
My true love gave to me
A partridge in a pear tree.
On the second day of Christmas
My true love gave to me
Two turtle doves, and
A partridge in a pear tree.
On the third day of Christmas
My true love gave to me
Three French hens,
Two turtle doves, and
A partridge in a pear tree.
Notes:
- I recommend defining private static final int lastVerse and setting it to 4 while testing. In fact, you may limit your program to four verses, if you prefer.
- You may approach this problem any way you wish, but you must not code any line of the program more than once. (In other words, the text "A partridge in a pear tree" may not appear more than once in your program.) You might want to consider using:
- A recursive method, printGifts, with an internal switch statement, to print the appropriate gifts for the day
- An array to store the names of the gifts (eliminating the need for the switch statement mentioned above)
- A String function named "ordinal" that returns the name of the ordinal number associated with its int parameter
- There is definitely no good reason to write one method for each verse. In fact, you'll lose design points if you do this.
Teacher's Comments
This assignment gets them thinking.
Contribute
If you would like to contribute your suggestions for nifty assignments, please submit your ideas.
|
|
|
|
|
|