Christmas countdown Java

Ads

 
 
 

Share on Google+Share on Google+

Ralph Wu
Christmas countdown Java
0 Answer(s)      3 years and 3 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();
    }}}}
Ads
View Answers
Ads









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  write a java program using filenotfoundexception
Java
Java  how to draw class diagrams in java
java
java   difference between class and interface
java
java  why multiple inheritance is not possible in java
java
java  explain object oriented concept in java
java
java  is java purely object oriented language
Tutorials   
Java Spring Hibernate Struts Training ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java

Ads

 
Advertisement null

Ads