Christmas countdown Java

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 Java
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... date: 12122014 Date is: December 12, 2014 Days until Christmas: 13 And here
Christmas countdown Java
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... date: 12122014 Date is: December 12, 2014 Days until Christmas: 13 And here
Advertisements
drawing a christmas tree - Java Beginners
drawing 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.
code for timer in java netbeans for online test series countdown timer
code for timer in java netbeans for online test series countdown timer  code for timer in java netbeans for online test series countdown timer
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 Island
Latitude 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
ModuleNotFoundError: No module named 'christmas-tree'
ModuleNotFoundError: No module named 'christmas-tree'  Hi, My... named 'christmas-tree' How to remove the ModuleNotFoundError: No module named 'christmas-tree' error? Thanks   Hi, In your python
How to design a countdown, design a countdown, countdown
How to design a countdown       It is a great opportunity to learn to draw count down symbol with the help of this example. New File: Insert a new document.ADS_TO_REPLACE_1
Countdown timer to show a link
Countdown 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
ModuleNotFoundError: No module named 'countdown-event'
ModuleNotFoundError: No module named 'countdown-event'  Hi, My... named 'countdown-event' How to remove the ModuleNotFoundError: No module named 'countdown-event' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'countdown-event'
ModuleNotFoundError: No module named 'countdown-event'  Hi, My... named 'countdown-event' How to remove the ModuleNotFoundError: No module named 'countdown-event' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'countdown-event'
ModuleNotFoundError: No module named 'countdown-event'  Hi, My... named 'countdown-event' How to remove the ModuleNotFoundError: No module named 'countdown-event' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'countdown-slackbot'
ModuleNotFoundError: No module named 'countdown-slackbot'  Hi, My... named 'countdown-slackbot' How to remove the ModuleNotFoundError: No module named 'countdown-slackbot' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'countdown-slackbot'
ModuleNotFoundError: No module named 'countdown-slackbot'  Hi, My... named 'countdown-slackbot' How to remove the ModuleNotFoundError: No module named 'countdown-slackbot' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'countdown-event'
ModuleNotFoundError: No module named 'countdown-event'  Hi, My... named 'countdown-event' How to remove the ModuleNotFoundError: No module named 'countdown-event' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'countdown-slackbot'
ModuleNotFoundError: No module named 'countdown-slackbot'  Hi, My... named 'countdown-slackbot' How to remove the ModuleNotFoundError: No module named 'countdown-slackbot' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'easy-countdown'
ModuleNotFoundError: No module named 'easy-countdown'  Hi, My... named 'easy-countdown' How to remove the ModuleNotFoundError: No module named 'easy-countdown' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'fluentcms-countdown'
ModuleNotFoundError: No module named 'fluentcms-countdown'  Hi, My... named 'fluentcms-countdown' How to remove the ModuleNotFoundError: No module named 'fluentcms-countdown' error? Thanks   Hi
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
ModuleNotFoundError: No module named 'wg-countdown-timer'
ModuleNotFoundError: No module named 'wg-countdown-timer'  Hi, My... named 'wg-countdown-timer' How to remove the ModuleNotFoundError: No module named 'wg-countdown-timer' error? Thanks   Hi, In your
Jsp count and java bean - JSP-Servlet
Jsp 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 Help
Java 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
java
java  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 Beginners
Inheretance 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
JQuery
JQuery  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 Beginners
Inheretance 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
Loops
Loops  ï??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
java
java  diff bt core java and java
java
java  what is java
JAVA
JAVA  how the name came for java language as "JAVA
java
java   why iterator in java if we for loop
java
java  explain technologies are used in java now days and structure java
java
java  different between java & core java
Java
Java   Whether Java is pure object oriented Language
java
java  is java open source
java
java  what is java reflection
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java  give a simple example for inheritance in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java   What is ?static? keyword

Ads