/** * The java program TwelveDays that prompts user to enter * last day number then prints the verse of christmas song * to console. * */ //TwelveDays.java import java.util.Scanner; public class TwelveDays { public static void main(String[] args) { final int MAX = 12; int lastDay = 0; //last day for the song, user will update //create a scanner class object Scanner scanner = new Scanner(System.in); //Get the last day and use input validation do { //prompt for lastDay value System.out.println(\"Enter last day number [1-12]\"); lastDay=Integer.parseInt(scanner.nextLine()); }while(lastDay<1 || lastDay>12); //set lastDay to day int day = lastDay; System.out.print(\"On the \"); //first switch case switch(day) { case 1: System.out.print(\"first \"); break; case 2: System.out.print(\"second\"); break; case 3: System.out.print(\"third\"); break; case 4: System.out.print(\"fourth\"); break; case 5: System.out.print(\"fifth\"); break; case 6: System.out.print(\"sixth\"); break; case 7: System.out.print(\"seventh\"); break; case 8: System.out.print(\"eighth\"); break; case 9: System.out.print(\"ninth\"); break; case 10: System.out.print(\"tenth\"); break; case 11: System.out.print(\"eleventh\"); break; case 12: System.out.print(\"twelfth\"); break; } System.out.println(\" day of Christmas, my true love sent to me:\"); //second switch case to select gift of day switch(day) { case 12: System.out.println(\"Twelve Drummers Drumming\"); case 11: System.out.println(\"Eleven Pipers Piping\"); case 10: System.out.println(\"Ten Lords a Leaping\"); case 9: System.out.println(\"Nine Ladies Dancing\"); case 8: System.out.println(\"Eight Maids a Milking\"); case 7: System.out.println(\"Seven Swans a Swimming\"); case 6: System.out.println(\"Six Geese a Laying\"); case 5: System.out.println(\"Five Golden Rings\"); case 4: System.out.println(\"Four Calling Birds\"); case 3: System.out.println(\"Three French Hens\"); case 2: System.out.print(\"Two Turtle Doves\"); case 1: if(day>1){ System.out.println(\",and \"); } System.out.println(\"A Partridge in a Pear Tree.\"); break; } } }//end of the class ------------------------------------------------------------------------------------------------------ Sample output: Enter last day number [1-12] 12 On the twelfth day of Christmas, my true love sent to me: Twelve Drummers Drumming 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. sample run2\" Enter last day number [1-12] 11 On the eleventh day of Christmas, my true love sent to me: 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. Solution /** * The java program TwelveDays that prompts user to enter * last day number then.