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