SlideShare a Scribd company logo
/**
* 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 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.

More Related Content

Similar to The java program TwelveDays that prompts user to enter l.pdf

Create a class named Student that has the following member variables.pdf
Create a class named Student that has the following member variables.pdfCreate a class named Student that has the following member variables.pdf
Create a class named Student that has the following member variables.pdf
arrowvisionoptics
 
The java program that prompts user to enter a string and .pdf
  The java program that prompts user to  enter a string and .pdf  The java program that prompts user to  enter a string and .pdf
The java program that prompts user to enter a string and .pdf
DEEPAKSONI562
 
PROGRAMING IN JAVA 4TH SEM DIGVIJAY COLLAGE
PROGRAMING IN JAVA 4TH SEM DIGVIJAY COLLAGEPROGRAMING IN JAVA 4TH SEM DIGVIJAY COLLAGE
PROGRAMING IN JAVA 4TH SEM DIGVIJAY COLLAGE
yash production
 
OBJECT ORIENTED PROGRAMMIING LANGUAGE PROGRAMS
OBJECT ORIENTED PROGRAMMIING LANGUAGE PROGRAMSOBJECT ORIENTED PROGRAMMIING LANGUAGE PROGRAMS
OBJECT ORIENTED PROGRAMMIING LANGUAGE PROGRAMS
Rohit Kumar
 
ConvertingSeconds.javaimport java.util.Scanner;public class Conv.pdf
ConvertingSeconds.javaimport java.util.Scanner;public class Conv.pdfConvertingSeconds.javaimport java.util.Scanner;public class Conv.pdf
ConvertingSeconds.javaimport java.util.Scanner;public class Conv.pdf
angelfashions02
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
arshiartpalace
 
Digits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdfDigits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdf
annapurnnatextailes
 
package reservation; import java.util.; For Scanner Class .pdf
 package reservation; import java.util.; For Scanner Class .pdf package reservation; import java.util.; For Scanner Class .pdf
package reservation; import java.util.; For Scanner Class .pdf
anitasahani11
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
Aiman Hud
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
mayorothenguyenhob69
 
java program assigment -1
java program assigment -1java program assigment -1
java program assigment -1
Ankit Gupta
 
wk2utility classes.zipApplicationUtilities.csusing System.docx
wk2utility classes.zipApplicationUtilities.csusing System.docxwk2utility classes.zipApplicationUtilities.csusing System.docx
wk2utility classes.zipApplicationUtilities.csusing System.docx
ericbrooks84875
 
PROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docxPROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docx
MohamoudAbdiHussein
 
Quest 1 define a class batsman with the following specifications
Quest  1 define a class batsman with the following specificationsQuest  1 define a class batsman with the following specifications
Quest 1 define a class batsman with the following specifications
rajkumari873
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
Iram Ramrajkar
 
Hadoop Installation_13_09_2022(1).docx
Hadoop Installation_13_09_2022(1).docxHadoop Installation_13_09_2022(1).docx
Hadoop Installation_13_09_2022(1).docx
1MS20CS406
 
Java oops features
Java oops featuresJava oops features
Java oops features
VigneshManikandan11
 

Similar to The java program TwelveDays that prompts user to enter l.pdf (17)

Create a class named Student that has the following member variables.pdf
Create a class named Student that has the following member variables.pdfCreate a class named Student that has the following member variables.pdf
Create a class named Student that has the following member variables.pdf
 
The java program that prompts user to enter a string and .pdf
  The java program that prompts user to  enter a string and .pdf  The java program that prompts user to  enter a string and .pdf
The java program that prompts user to enter a string and .pdf
 
PROGRAMING IN JAVA 4TH SEM DIGVIJAY COLLAGE
PROGRAMING IN JAVA 4TH SEM DIGVIJAY COLLAGEPROGRAMING IN JAVA 4TH SEM DIGVIJAY COLLAGE
PROGRAMING IN JAVA 4TH SEM DIGVIJAY COLLAGE
 
OBJECT ORIENTED PROGRAMMIING LANGUAGE PROGRAMS
OBJECT ORIENTED PROGRAMMIING LANGUAGE PROGRAMSOBJECT ORIENTED PROGRAMMIING LANGUAGE PROGRAMS
OBJECT ORIENTED PROGRAMMIING LANGUAGE PROGRAMS
 
ConvertingSeconds.javaimport java.util.Scanner;public class Conv.pdf
ConvertingSeconds.javaimport java.util.Scanner;public class Conv.pdfConvertingSeconds.javaimport java.util.Scanner;public class Conv.pdf
ConvertingSeconds.javaimport java.util.Scanner;public class Conv.pdf
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
 
Digits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdfDigits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdf
 
package reservation; import java.util.; For Scanner Class .pdf
 package reservation; import java.util.; For Scanner Class .pdf package reservation; import java.util.; For Scanner Class .pdf
package reservation; import java.util.; For Scanner Class .pdf
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
java program assigment -1
java program assigment -1java program assigment -1
java program assigment -1
 
wk2utility classes.zipApplicationUtilities.csusing System.docx
wk2utility classes.zipApplicationUtilities.csusing System.docxwk2utility classes.zipApplicationUtilities.csusing System.docx
wk2utility classes.zipApplicationUtilities.csusing System.docx
 
PROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docxPROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docx
 
Quest 1 define a class batsman with the following specifications
Quest  1 define a class batsman with the following specificationsQuest  1 define a class batsman with the following specifications
Quest 1 define a class batsman with the following specifications
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
 
Hadoop Installation_13_09_2022(1).docx
Hadoop Installation_13_09_2022(1).docxHadoop Installation_13_09_2022(1).docx
Hadoop Installation_13_09_2022(1).docx
 
Java oops features
Java oops featuresJava oops features
Java oops features
 

More from htanandpalace

PV = n(total) RT n = 1.09 8.90 0.0821 298 = .pdf
                     PV = n(total) RT n = 1.09  8.90  0.0821 298 = .pdf                     PV = n(total) RT n = 1.09  8.90  0.0821 298 = .pdf
PV = n(total) RT n = 1.09 8.90 0.0821 298 = .pdf
htanandpalace
 
Looks like C is meso. Everything else looks good!.pdf
                     Looks like C is meso. Everything else looks good!.pdf                     Looks like C is meso. Everything else looks good!.pdf
Looks like C is meso. Everything else looks good!.pdf
htanandpalace
 
Mass is the amount of material in an object or ho.pdf
                     Mass is the amount of material in an object or ho.pdf                     Mass is the amount of material in an object or ho.pdf
Mass is the amount of material in an object or ho.pdf
htanandpalace
 
What precisely is huge data A report delivered to the U.S. Congress.pdf
What precisely is huge data A report delivered to the U.S. Congress.pdfWhat precisely is huge data A report delivered to the U.S. Congress.pdf
What precisely is huge data A report delivered to the U.S. Congress.pdf
htanandpalace
 
wireless communication -wireless communication is the transfer of.pdf
wireless communication -wireless communication is the transfer of.pdfwireless communication -wireless communication is the transfer of.pdf
wireless communication -wireless communication is the transfer of.pdf
htanandpalace
 
THe H2O2 concentration might be low as some H2O2 may decompose by ta.pdf
THe H2O2 concentration might be low as some H2O2 may decompose by ta.pdfTHe H2O2 concentration might be low as some H2O2 may decompose by ta.pdf
THe H2O2 concentration might be low as some H2O2 may decompose by ta.pdf
htanandpalace
 
The Differential equation isdydx +ay = alphaxe-axIF = eaxHenc.pdf
The Differential equation isdydx +ay = alphaxe-axIF = eaxHenc.pdfThe Differential equation isdydx +ay = alphaxe-axIF = eaxHenc.pdf
The Differential equation isdydx +ay = alphaxe-axIF = eaxHenc.pdf
htanandpalace
 
Supertrampsspecies in the play imprtant role in the environment, bec.pdf
Supertrampsspecies in the play imprtant role in the environment, bec.pdfSupertrampsspecies in the play imprtant role in the environment, bec.pdf
Supertrampsspecies in the play imprtant role in the environment, bec.pdf
htanandpalace
 
The act had a profound effect on corporate governance in the United .pdf
The act had a profound effect on corporate governance in the United .pdfThe act had a profound effect on corporate governance in the United .pdf
The act had a profound effect on corporate governance in the United .pdf
htanandpalace
 
Statistical DistributionsEvery statistics book provides a list.pdf
Statistical DistributionsEvery statistics book provides a list.pdfStatistical DistributionsEvery statistics book provides a list.pdf
Statistical DistributionsEvery statistics book provides a list.pdf
htanandpalace
 
second student expressed in better formhe made z independant, and .pdf
second student expressed in better formhe made z independant, and .pdfsecond student expressed in better formhe made z independant, and .pdf
second student expressed in better formhe made z independant, and .pdf
htanandpalace
 
AnswerProperties area.) Enthalpy, c.) Mass, e.) DensitySolu.pdf
AnswerProperties area.) Enthalpy, c.) Mass, e.) DensitySolu.pdfAnswerProperties area.) Enthalpy, c.) Mass, e.) DensitySolu.pdf
AnswerProperties area.) Enthalpy, c.) Mass, e.) DensitySolu.pdf
htanandpalace
 
in He2 there are total of four electrons which can be placed on both.pdf
in He2 there are total of four electrons which can be placed on both.pdfin He2 there are total of four electrons which can be placed on both.pdf
in He2 there are total of four electrons which can be placed on both.pdf
htanandpalace
 
I think that 24SolutionI think that 24.pdf
I think that 24SolutionI think that 24.pdfI think that 24SolutionI think that 24.pdf
I think that 24SolutionI think that 24.pdf
htanandpalace
 
For n=1,2,3 ;SolutionFor n=1,2,3 ;.pdf
For n=1,2,3 ;SolutionFor n=1,2,3 ;.pdfFor n=1,2,3 ;SolutionFor n=1,2,3 ;.pdf
For n=1,2,3 ;SolutionFor n=1,2,3 ;.pdf
htanandpalace
 
Egg polarity is the orientation of the egg. In developmental biology.pdf
Egg polarity is the orientation of the egg. In developmental biology.pdfEgg polarity is the orientation of the egg. In developmental biology.pdf
Egg polarity is the orientation of the egg. In developmental biology.pdf
htanandpalace
 
Every network and system has some loop holes and weaknesses so the i.pdf
Every network and system has some loop holes and weaknesses so the i.pdfEvery network and system has some loop holes and weaknesses so the i.pdf
Every network and system has some loop holes and weaknesses so the i.pdf
htanandpalace
 
COOH and NH2SolutionCOOH and NH2.pdf
COOH and NH2SolutionCOOH and NH2.pdfCOOH and NH2SolutionCOOH and NH2.pdf
COOH and NH2SolutionCOOH and NH2.pdf
htanandpalace
 
confounding -- they are both caused by something else - wealth.pdf
confounding -- they are both caused by something else - wealth.pdfconfounding -- they are both caused by something else - wealth.pdf
confounding -- they are both caused by something else - wealth.pdf
htanandpalace
 
a. Journal entry fro revaluation of assetb. Journal entry for admi.pdf
a. Journal entry fro revaluation of assetb. Journal entry for admi.pdfa. Journal entry fro revaluation of assetb. Journal entry for admi.pdf
a. Journal entry fro revaluation of assetb. Journal entry for admi.pdf
htanandpalace
 

More from htanandpalace (20)

PV = n(total) RT n = 1.09 8.90 0.0821 298 = .pdf
                     PV = n(total) RT n = 1.09  8.90  0.0821 298 = .pdf                     PV = n(total) RT n = 1.09  8.90  0.0821 298 = .pdf
PV = n(total) RT n = 1.09 8.90 0.0821 298 = .pdf
 
Looks like C is meso. Everything else looks good!.pdf
                     Looks like C is meso. Everything else looks good!.pdf                     Looks like C is meso. Everything else looks good!.pdf
Looks like C is meso. Everything else looks good!.pdf
 
Mass is the amount of material in an object or ho.pdf
                     Mass is the amount of material in an object or ho.pdf                     Mass is the amount of material in an object or ho.pdf
Mass is the amount of material in an object or ho.pdf
 
What precisely is huge data A report delivered to the U.S. Congress.pdf
What precisely is huge data A report delivered to the U.S. Congress.pdfWhat precisely is huge data A report delivered to the U.S. Congress.pdf
What precisely is huge data A report delivered to the U.S. Congress.pdf
 
wireless communication -wireless communication is the transfer of.pdf
wireless communication -wireless communication is the transfer of.pdfwireless communication -wireless communication is the transfer of.pdf
wireless communication -wireless communication is the transfer of.pdf
 
THe H2O2 concentration might be low as some H2O2 may decompose by ta.pdf
THe H2O2 concentration might be low as some H2O2 may decompose by ta.pdfTHe H2O2 concentration might be low as some H2O2 may decompose by ta.pdf
THe H2O2 concentration might be low as some H2O2 may decompose by ta.pdf
 
The Differential equation isdydx +ay = alphaxe-axIF = eaxHenc.pdf
The Differential equation isdydx +ay = alphaxe-axIF = eaxHenc.pdfThe Differential equation isdydx +ay = alphaxe-axIF = eaxHenc.pdf
The Differential equation isdydx +ay = alphaxe-axIF = eaxHenc.pdf
 
Supertrampsspecies in the play imprtant role in the environment, bec.pdf
Supertrampsspecies in the play imprtant role in the environment, bec.pdfSupertrampsspecies in the play imprtant role in the environment, bec.pdf
Supertrampsspecies in the play imprtant role in the environment, bec.pdf
 
The act had a profound effect on corporate governance in the United .pdf
The act had a profound effect on corporate governance in the United .pdfThe act had a profound effect on corporate governance in the United .pdf
The act had a profound effect on corporate governance in the United .pdf
 
Statistical DistributionsEvery statistics book provides a list.pdf
Statistical DistributionsEvery statistics book provides a list.pdfStatistical DistributionsEvery statistics book provides a list.pdf
Statistical DistributionsEvery statistics book provides a list.pdf
 
second student expressed in better formhe made z independant, and .pdf
second student expressed in better formhe made z independant, and .pdfsecond student expressed in better formhe made z independant, and .pdf
second student expressed in better formhe made z independant, and .pdf
 
AnswerProperties area.) Enthalpy, c.) Mass, e.) DensitySolu.pdf
AnswerProperties area.) Enthalpy, c.) Mass, e.) DensitySolu.pdfAnswerProperties area.) Enthalpy, c.) Mass, e.) DensitySolu.pdf
AnswerProperties area.) Enthalpy, c.) Mass, e.) DensitySolu.pdf
 
in He2 there are total of four electrons which can be placed on both.pdf
in He2 there are total of four electrons which can be placed on both.pdfin He2 there are total of four electrons which can be placed on both.pdf
in He2 there are total of four electrons which can be placed on both.pdf
 
I think that 24SolutionI think that 24.pdf
I think that 24SolutionI think that 24.pdfI think that 24SolutionI think that 24.pdf
I think that 24SolutionI think that 24.pdf
 
For n=1,2,3 ;SolutionFor n=1,2,3 ;.pdf
For n=1,2,3 ;SolutionFor n=1,2,3 ;.pdfFor n=1,2,3 ;SolutionFor n=1,2,3 ;.pdf
For n=1,2,3 ;SolutionFor n=1,2,3 ;.pdf
 
Egg polarity is the orientation of the egg. In developmental biology.pdf
Egg polarity is the orientation of the egg. In developmental biology.pdfEgg polarity is the orientation of the egg. In developmental biology.pdf
Egg polarity is the orientation of the egg. In developmental biology.pdf
 
Every network and system has some loop holes and weaknesses so the i.pdf
Every network and system has some loop holes and weaknesses so the i.pdfEvery network and system has some loop holes and weaknesses so the i.pdf
Every network and system has some loop holes and weaknesses so the i.pdf
 
COOH and NH2SolutionCOOH and NH2.pdf
COOH and NH2SolutionCOOH and NH2.pdfCOOH and NH2SolutionCOOH and NH2.pdf
COOH and NH2SolutionCOOH and NH2.pdf
 
confounding -- they are both caused by something else - wealth.pdf
confounding -- they are both caused by something else - wealth.pdfconfounding -- they are both caused by something else - wealth.pdf
confounding -- they are both caused by something else - wealth.pdf
 
a. Journal entry fro revaluation of assetb. Journal entry for admi.pdf
a. Journal entry fro revaluation of assetb. Journal entry for admi.pdfa. Journal entry fro revaluation of assetb. Journal entry for admi.pdf
a. Journal entry fro revaluation of assetb. Journal entry for admi.pdf
 

Recently uploaded

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 

Recently uploaded (20)

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 

The java program TwelveDays that prompts user to enter l.pdf

  • 1. /** * 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;
  • 2. 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:
  • 3. 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
  • 4. 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 prints the verse of christmas song * to console. * */ //TwelveDays.java
  • 5. 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:
  • 6. 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");
  • 7. 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
  • 8. 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.