Christmas countdown Java
Assignment:
Write a program that reads in a date and calculates the number of days until Christmas for that year .
You can assume that the date entered is before December 25 of that year.
Dates will be entered as 8 digit numbers representing: MMDDYYYY
You are not allow to use arrays, Date, or Time.
Here is a sample input and its corresponding output:
Enter date: 12122014
Date is: December 12, 2014
Days until Christmas: 13
And here is my work:
public static void main(String[] args)
{
//declaring variables
System.out.print("Enter Date: ");
Scanner scan = new Scanner( System.in );
int date = scan.nextInt();
int year = date%10000;
date = date/10000;
int day = date %100;
int month = date/100;
int numdays =
int daystil = //days until christmas
int month;
String monthString;
//Classifying months
switch( month )
{
case 1 : monthString = "January";break;
case 2 : monthString = "February";break;
case 3 : monthString = "March";break;
case 4 : monthString = "April";break;
case 5 : monthString = "May";break;
case 6 : monthString = "June";break;
case 7 : monthString = "July";break;
case 8 : monthString = "August";break;
case 9 : monthString = "September";break;
case 10 : monthString = "October";break;
case 11 : monthString = "November";break;
case 12 : monthString = "December";break;
String daystilString;
switch ( daystil )
{
case 1 : daystilString = if ((year % 4 == 0) && !(year % 100 == 0) || (year % 400 == 0)){
360-day;
}else ;{
359-day;
}
case 2 : daystilString = if ((year % 4 == 0) && !(year % 100 == 0) || (year % 400 == 0)){
329-day;
}else;{
328-day;
case 3 : daystilString = 300-day;
case 4 : daystilString = 269-day;
case 5 : daystilString = 239-day;
case 6 : daystilString = 208-day;
case 7 : daystilString = 178-day;
case 8 : daystilString = 147-day;
case 9 : dasytilString = 116-day;
case 10 : daystilString = 86-day;
case 11 : daystilString = 55-day;
case 12 : daystilString = 25-day;
}break;
default: System.out.println("Invalid month.");
if (month == 1){
System.out.println("Date is: January ");
System.out.format("%f, ", day);
System.out.format("%f", year);
System.out.format("\nDays until Christmas: ", daystil);
}else if (month == 2) {
System.out.println("Date is: February");
System.out.format("%f, ", day);
System.out.format("%f", year);
System.out.format("\nDays until Christmas: ", daystil);
}else if (month == 3){
System.out.println("Date is: March");
System.out.format("%f, ", day);
System.out.format("%f", year);
System.out.format("\nDays until Christmas: ", daystil);
}else if (month == 4){
System.out.println("Date is: April");
System.out.format("%f, ", day);
System.out.format("%f", year);
System.out.format("\nDays until Christmas: ", daystil);
}else if (month == 5){
System.out.println("Date is: May");
System.out.format("%f, ", day);
System.out.format("%f", year);
System.out.format("\nDays until Christmas: ", daystil);
}else if (month == 6){
System.out.println("Date is: June");
System.out.format("%f, ", day);
System.out.format("%f", year);
System.out.format("\nDays until Christmas: ", daystil);
}else if (month == 7){
System.out.println("Date is: July");
System.out.format("%f, ", day);
System.out.format("%f", year);
System.out.format("\nDays until Christmas: ", daystil);
}else if (month == 8){
System.out.println("Date is: August");
System.out.format("%f, ", day);
System.out.format("%f", year);
System.out.format("\nDays until Christmas: ", daystil);
}else if (month == 9){
System.out.println("Date is: September");
System.out.format("%f, ", day);
System.out.format("%f", year);
System.out.format("\nDays until Christmas: ", daystil);
}else if (month == 10){
System.out.println("Date is: October");
System.out.format("%f, ", day);
System.out.format("%f", year);
System.out.format("\nDays until Christmas: ", daystil);
}else if (month == 11){
System.out.println("Date is: November");
System.out.format("%f, ", day);
System.out.format("%f", year);
System.out.format("\nDays until Christmas: ", daystil);
}else if (month == 12){
System.out.println("Date is: December");
System.out.format("%f, ", day);
System.out.format("%f", year);
System.out.format("\nDays until Christmas: ", daystil);
}else if ((month == 12) && (day == 25));{
System.out.println("Date is: December");
System.out.format("%f, ", day);
System.out.format("%f", year);
System.out.println("\nMerry Christmans!");
}else if ((month == 12) && (day >= 26));{
System.out.println("Date is: December");
System.out.format("%f, ", day);
System.out.format("%f", year);
System.out.println("\nInvalid input.");
}
scan.close();
}}}}
View Answers
Related Tutorials/Questions & Answers:
Christmas countdown JavaChristmas countdown Java Assignment:
Write a program that reads in a date and calculates the number of days until
Christmas for that year .
You can... date: 12122014
Date is: December 12, 2014
Days until
Christmas: 13
And here
Christmas countdown JavaChristmas countdown Java Assignment:
Write a program that reads in a date and calculates the number of days until
Christmas for that year .
You can... date: 12122014
Date is: December 12, 2014
Days until
Christmas: 13
And here
Advertisements
drawing a christmas tree - Java Beginnersdrawing a
christmas tree how do i write a program that draws a chrimas tree using the knowledge of loops only. i.e * *** ***** ******* the program will draw a Christ mas tree Hi ChristmasTree.javaimport java.awt.
ModuleNotFoundError: No module named 'christmas'ModuleNotFoundError: No module named '
christmas' Hi,
My Python... '
christmas'
How to remove the ModuleNotFoundError: No module named '
christmas' error?
Thanks
Hi,
In your python environment you
Latitude and Longitude of Christmas IslandLatitude and Longitude of
Christmas Island Hi,
What is the Latitude and Longitude on
Christmas Island?
Thanks
Hi,
Latitude of
Christmas Island is:-10.5 and
Longitude of
Christmas Island is: 105.6667
Discovered
ModuleNotFoundError: No module named 'countdown'ModuleNotFoundError: No module named '
countdown' Hi,
My Python... '
countdown'
How to remove the ModuleNotFoundError: No module named '
countdown' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'countdown'ModuleNotFoundError: No module named '
countdown' Hi,
My Python... '
countdown'
How to remove the ModuleNotFoundError: No module named '
countdown' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'countdown'ModuleNotFoundError: No module named '
countdown' Hi,
My Python... '
countdown'
How to remove the ModuleNotFoundError: No module named '
countdown' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'countdown'ModuleNotFoundError: No module named '
countdown' Hi,
My Python... '
countdown'
How to remove the ModuleNotFoundError: No module named '
countdown' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'countdown'ModuleNotFoundError: No module named '
countdown' Hi,
My Python... '
countdown'
How to remove the ModuleNotFoundError: No module named '
countdown' error?
Thanks
Hi,
In your python environment you
Countdown timer to show a linkCountdown timer to show a link Hi to everyone! I have this code, which is basically a
countdown widget...what I want is that when the
countdown... whitin a month and a half, and we want this
countdown to be in the website
javascript timer countdown timer
countdown?
<!-- CSS Code -->
#txt {
border:none;
font...;Generally, the timer
countdown, is required to stop user of doing something after a certain period of time. The above given example "javascript timer
countdown" allows
Jsp count and java bean - JSP-ServletJsp count and
java bean Please am on a project and i want to create a
countdown timer that will have this format HH:MM:SS. Am working with jsp and
java beans please somebody help. Hi Friend,
Try the following
Inner class - Java Interview Questions the problem :
class InnerClass1 {
private int
countDown = 5;
private...() {
while (true) {
System.out.println(this);
if (--
countDown == 0...() + ": " +
countDown;
}
}
public InnerClass1(String name) {
inner = new Inner
Java Script HelpJava Script Help I have written a
countdown timer using javascript as Countdown.html.
It works fine in Mozila Firefox. But Not working in IE. Pls....'
window.location = 'crdtd.php?
q=b
javajava pleasse help me...
write a program that produces
christmas trees output. It should have a method with 2 parameters, one for the number of segment in the trees and one for the heightof each segment for example, the treees
Inheretance and polymorphism - Java BeginnersInheretance and polymorphism hope guys you will help ,thank you. merry
christmas and happy new year to you!
Exercise 1.) A point the x-y plane... information on
Java Visit to :
http://www.roseindia.net/
java/
java-conversion/how
Inheretance and polymorphism - Java Beginners. merry
christmas and happy new year to you!
1.) A point the x-y plane... information.
http://www.roseindia.net/
java/language/inheritance.shtml
http://www.roseindia.net/
java/beginners/oop-in-java.shtml
Thanks
JQueryJQuery How to create time
countdown ? which will start on click start button and pause on click pause button . also compatible to all browser
Inheretance and polymorphism - Java BeginnersInheretance and polymorphism FRIEND IS THIS ONE CODE???
hope guys you will help ,thank you. merry
christmas and happy new year to you!
1.) A point the x-y plane is coordinate and y-coordinate.Design the class Point
LoopsLoops ï??Using for loops, Write a program to simulate
a clock
countdown. The program prompts the
user to enter the number of seconds, displays
a message at every second, and terminates
when the time expires. Use method
javajava diff bt core
java and
java JAVAJAVA how the name came for
java language as "
JAVA java java why iterator in
java if we for loop
javajava explain technologies are used in
java now days and structure
java javajava different between
java & core
java Java Java Whether
Java is pure object oriented Language
javajava is
java open source
javajava what is
java reflection
java java in
java does not pointers concept but what is nullpointers in
java?
nullpointer is a runtime Exception
javawhat is the size of array in
java ? what is the size of array in
java ?
what is the mean of finalize in
java javajava give a simple example for inheritance in
java javajava why to set classpath in
java javajava why to set classpath in
java javajava why to set classpath in
java java java What is ?static? keyword