Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

7.11111111 program requirements As a reminder, you should be including comments

ID: 3856236 • Letter: 7

Question

7.11111111 program requirements

As a reminder, you should be including comments in your programs . Comments should be placed periodically throughout your program. Your comments should explain the logic of what you are doing. You do not need to write comments before every line in your program. Instead, you should add comments at the beginning of a section of code to explain what the next few lines are trying to accomplish.

Pay close attention to the directions!! Make absolutely certain that you are doing exactly what the assignment asks you to do. If you don't understand the problem, make sure to ask your instructor or an assistant.

part 1

Begin by creating a new Java project.

Create a new Java class inside your project folder.
The name of the class should be: TwelveDays

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.

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.

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
.

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 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.

Hint

Order the cases carefully to avoid using the break statement.

Explanation / Answer

import java.util.*;      
import java.lang.*;      
import java.io.*;      
class TwelveDays     
{      
   public static void main (String[] args) throws java.lang.Exception  
   {  
         
       Scanner reader = new Scanner(System.in);  
        System.out.print("Enter a day: ");        
        int day= reader.nextInt();     // Here taking input from the user      
              
       if(day<=12) // Here checking condition wether entered input is with in the day limit or not  
       {  
        for(int i=1; i<=day; i++) // loop execution  
        {  
          
            System.out.print("On the ");      
      
            switch(i) // this swith case divide the "st", "nd", "rd" and print the statement.      
            {      
                case 1: System.out.print("1st"); break;      
                case 2: System.out.print("2nd"); break;      
                case 3: System.out.print("3rd"); break;      
                default: System.out.print(i+"th");      
      
            }      
      
            System.out.println(" day of Christmas my true love gave to me");      
      
            switch(i)    // This switch statement for printing song lines.      
            {      
               case 12: System.out.print("Twelve drummers drumming, ");  
               case 11: System.out.print("Eleven pipers piping, ");  
               case 10: System.out.print("Ten lords a leaping, ");  
               case 9: System.out.print("Nine ladies dancing, ");  
               case 8: System.out.print("Eight maids a milking, ");      
               case 7: System.out.print("Seven swans a swimming, ");  
               case 6: System.out.print("Six geese a laying, ");  
               case 5: System.out.print("Five golden rings, ");  
               case 4: System.out.print("Four calling birds, ");  
               case 3: System.out.print("Three French hens, ");  
               case 2: System.out.print("Two turtle doves, and ");  
               case 1: System.out.println("A partridge in a pear tree. ");  
      
            }      
            pause();      
        }  
       }  
        else  
        {  
            System.out.print("Please enter valid input ");  
        }  
      
    }      
    public static void pause() // This is method to give print statment and pause.      
    {      
    System.out.println("Press enter to continue...");      
    Scanner keyboard = new Scanner(System.in);      
    keyboard.nextLine();      
    }      
}

Note: In the above mentioned programme, i am using method for giving pause. Please check it once.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote