// TwelveDays2.java // rewrite TwelveDays.java using arrays public class TwelveDays2 { // define class constants private static final String[] nthName = { "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth" }; private static final String[] nthGift = { "a partridge in a pear tree.", "two turtle doves, and", "three french hens,", "four calling birds,", "five golden rings,", "six geese a-laying,", "seven swans a-swimming,", "eight maids a-milking,", "nine ladies dancing,", "ten lords a-leaping,", "eleven pipers piping,", "twelve drummers drumming," }; public void printVerse (int day) { System.out.println("On the " + nthName[day] + " day of Christmas,"); System.out.println("my true love sent to me,"); for (int j = day; j >= 0; j--) { System.out.println(nthGift[j]); } System.out.println(); } public void printAllVerses () { for (int i = 0; i < 12; i++) { printVerse(i); } } public static void main (String[] args) { new TwelveDays2().printAllVerses(); } }