I need the song to be printed out the way it would be sung. If I type in 2, it should print out:
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.
Instead of just:
On the second day of Christmas
My true love gave to me
Two turtle doves, and
A partridge in a pear tree.
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.
Instead of just:
On the second day of Christmas
My true love gave to me
Two turtle doves, and
A partridge in a pear tree.
public class RecursiveSong
{
public static void main(String [] args)
{
final int LAST_VERSE = 12;
String day = "";
switch (LAST_VERSE)
{
case 1:
day = "first";
break;
case 2:
day = "second";
break;
case 3:
day = "third";
break;
case 4:
day = "fourth";
break;
case 5:
day = "fifth";
break;
case 6:
day = "sixth";
break;
case 7:
day = "seventh";
break;
case 8:
day = "eighth";
break;
case 9:
day = "ninth";
break;
case 10:
day = "tenth";
break;
case 11:
day = "eleventh";
break;
case 12:
day = "twelth";
break;
}
System.out.println("On the " + day + " day of Christmas" + "\nMy true love gave to me");
String verse = RecursiveVerse(LAST_VERSE);
System.out.println(verse);
}
public static String RecursiveVerse(int DAY)
{
if (DAY == 0)
return "";
else
{
switch (DAY)
{
case 1:
System.out.println("A partridge in a pear tree");
break;
case 2:
System.out.println("Two turtle doves, and");
break;
case 3:
System.out.println("Three French Hens ");
break;
case 4:
System.out.println("Four calling birds");
break;
case 5:
System.out.println("Five golden rings");
break;
case 6:
System.out.println("Six geese a laying");
break;
case 7:
System.out.println("Seven swans a swimming");
break;
case 8:
System.out.println("Eight maids a milking");
break;
case 9:
System.out.println("Nine ladies dancing");
break;
case 10:
System.out.println("Ten lords a leaping");
break;
case 11:
System.out.println("Eleven pipers piping");
break;
case 12:
System.out.println("Twelve drummers drumming");
break;
}
return RecursiveVerse(DAY - 1);
}
}
}