Jump to page content Jump to navigation

College Board

AP Central

APAC 2009 Call For Proposals
AP Course Audit Web Site


Siemens Awards for Advanced Placement
Print Page
Home > AP Courses and Exams > Course Home Pages > Twelve Days of Christmas

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:
  1. 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.
  2. 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
  3. 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.


  ABOUT MY AP CENTRAL
    Course and Email Newsletter Preferences
  AP COURSES AND EXAMS
    Course Home Pages
    Course Descriptions
    The Course Audit
    Sample Syllabi
    Teachers' Resources
    Exam Calendar and Fees
    Exam Questions
    AP Credit Policy Information
  PRE-AP
    Teachers' Corner
    Publications
  AP COMMUNITY
    About Electronic Discussion Groups
    Become an AP Exam Reader

Back to top