Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a java application program that will print the verses of the song The Twelve Days of Christmas to the screen. In this song, each

Write a java application program that will print the verses of the song The Twelve Days of Christmas to the screen. In this song, each verse adds one additional line of output to the song.

The first verse should print the following:

On the 1st day of Christmas my true love gave to me A partridge in a pear tree. Press ENTER to continue

The second verse should print the following:

On the 2nd day of Christmas my true love gave to me Two turtle doves, and A partridge in a pear tree. Press ENTER to continue

The third verse should print the following:

On the 3rd day of Christmas my true love gave to me Three French hens, Two turtle doves, and A partridge in a pear tree. Press ENTER to continue

There are a total of 12 verses to the song, and each verse will add one additional line to the song. The final verse should print the following:

On the 12th day of Christmas my true love gave 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.

After each verse is printed, ask the user to press "ENTER" to continue.This will allow your program to pause after each verse to give the user time to read the verse before moving on to another. You should NOT ask the user to press "ENTER" after the last verse.

Program Restrictions

You CANNOT write tons of print statements to simply print out the entire song.

Your program MUST include a FOR loop. The loop should be designed to repeat exactly 12 times. Each trip through the loop should print one verse to the screen.

Inside the loop, you MUST use a SWITCH statements to control the lines that are printed to the screen.For the statement "On the Xth day of Christmas my true love gave to me":

Begin by printing "On the X" where X is the value of your loop counter.

Next, use a switch statement to print "st" or "nd" or "rd" or "th" to the screen. At this point, depending on the value of the loop counter, this will cause one of the following lines to be printed: On the 1st On the 2nd On the 3rd On the 4th etc.

Now, print the rest of the line to the screen: " day of Christmas my true love gave to me"

After the first line has been printed, use another switch statement to control which lines of the verse are printed to the screen. Each case statement is allowed to contain a single println statement so that each case statement is printing a single line of output to the screen.

You are not allowed to use more than one IF statement in this program. The only reason the IF statement is even needed is so that the program does not print "Press ENTER to continue" after the 12th verse.

If you receive a "No Element Exception" on the "Test Output" test, then it means that your program is looking for more input than the test is trying to give (i.e. make sure you are not asking the user to press enter after the 12th verse!)

Hint

Order the cases carefully to avoid using the break statement. Another way of thinking about this is that the words "A partridge in a pear tree." should not be seen in your program more than one time --- thus, you should be including these words on every verse. If your SWITCH statement is structured properly, you should only need one print statement in your program that will print this line.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Algorithmic Trading Navigating The Digital Frontier

Authors: Alex Thompson

1st Edition

B0CHXR6CXX, 979-8223284987

More Books

Students also viewed these Databases questions

Question

(2) f YZ (y, z).

Answered: 1 week ago

Question

4. Label problematic uses of language and their remedies

Answered: 1 week ago