Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Christmas countdown Java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ralph Wu
Christmas countdown Java
0 Answer(s)      8 months ago
Posted in : Java Beginners


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();
    }}}}

Advertisement
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
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. Insert
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
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
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-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
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
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
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
java
java  diff bt core java and java
java
java  what is java
java
java  different between java & core java
java
java  explain technologies are used in java now days and structure java
java
java   why iterator in java if we for loop
Java
Java   Whether Java is pure object oriented Language
JAVA
JAVA  how the name came for java language as "JAVA
java
java  what is java reflection
java
java  is java open source
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   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
Java
Java  how to draw class diagrams in java
java
java  explain object oriented concept in java
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  what are JAVA applications development tools
java
java  why to set classpath in java
java
java  give a simple example for inheritance in java
 

 

 

DMCA.com