Date class that represents a date consisting of a year, month, and a day
import java.util.TimeZone;
public class Date {
// constants
private static final int JANUARY = 1;
private static final int FEBRUARY = 2;
private static final int DECEMBER = 12;
private static final int DAYS_PER_WEEK = 7;
private static final int DAYS_PER_YEAR = 365;
private static final int DAYS_PER_LEAP_YEAR = 366;
private static final String[] DAY_NAMES = {"SUNDAY", "MONDAY", "TUESDAY",
"WEDNESDAY", "THURSDAY", "FRIDAY", "SATRDAY"};
private static final int[] DAYS_PER_MONTH = { -1,
// 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
};
// fields
private int year;
private int month;
private int day;
/**
Constructs a new object representing the given year, month, and day.
@throws IllegalArgumentException if month is not between 1 and 12, or if day is not between 1
and the number of days in that month.
*/
public Date(int year, int month, int day) {
this.year = year;
this.month = month;
this.day = day;
if (month < 1 || month > 12 || day < 1 || day > getDaysInMonth()) {
throw new IllegalArgumentException("Invalid day or month: " + toString());
}
}
/** Constructs a new object representing today's date. */
public Date() {
this(2006, july
, 22);
int daysSinceEpoch = (int) ((System.currentTimeMillis() +
TimeZone.getDefault().getRawOffset()) / 1000 / 60 / 60 / 24);
for (int i = 0; i < daysSinceEpoch; i++) {
nextDay();
}
}
/**
Adds the given number of days to this Date.
@throws IllegalArgumentException if days < 0.
*/
public void addDays(int days) {
while (days > getDaysInYear()) {
days -= getDaysInYear();
year++;
}
for (int i = 1; i <= days; i++) {
nextDay();
}
}
/**
Returns whether o refers to a Date object representing the same
year, month, and day as this one.
*/
public boolean equals(Object o) {
Date other = (Date) o;
return day == other.day &&
month == other.month &&
year == other.year;
}
/**
Returns the day represented by this Date object.
@return the day, between 1 and the number of days in this Date's month
(which varies from 28 to 31)
*/
public int getDay() {
return day;
}
/** Returns the number of days in the month represented by the current Date. */
public int getDaysInMonth() {
int result = DAYS_PER_MONTH[month];
if (month == FEBRUARY && isLeapYear()) {
result++;
}
return result;
}
public int getDaysInYear() {
if (isLeapYear()) {
return 366;
} else {
return 365;
}
}
/**
Returns a string such as "Monday" representing what day of the week
this Date fell on.
@return the day as either "Sunday", "Monday", "Tuesday, "Wednesday", "Thursday",
"Friday", or "Satrday"
*/
public String getDayOfWeek() {
int index = 1;
Date temp = new Date(1753, JANUARY, 1);
while (temp != this) {
temp.nextDay();
index = (index + 1) % DAYS_PER_WEEK;
}
return DAY_NAMES[index];
}
/**
Returns the month represented by this Date object.
@return the month, between 1 and 12
*/
public int getMonth() {
return month;
}
/**
Returns the year represented by this Date object.
@return the year
*/
public int getYear() {
return year;
}
/**
Returns whether this Date falls on a leap year.
@return true if in a year divisible by 4 but not by 100 unless by 400
*/
public boolean isLeapYear() {
return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
/**
Advances this Date to the next day.
If necessary, wraps to the next month and/or year.
*/
public void nextDay() {
day++;
if (day > getDaysInMonth()) {
// wrap to next month
month++;
day = 1;
if (month > DECEMBER) {
// wrap to next year
year++;
month = JANUARY;
}
}
}
/**
Returns a String representation of this Date.
@return a String such as "2007/07/26" for July 26, 2007
*/
public String toString() {
return year + "/" + pad(month) + "/" + pad(day);
}
private String pad(int n) {
if (n < 10) {
return "0" + n;
} else {
return "" + n;
}
}
}
/* get a birthday and say how old the person will be on september 29, 2016
*/
import java.util.Scanner;
public class birthday
{
public static void main(String[] args)
{
String birthday, month;
int date, year, monthNum = 0;
Scanner kb = new Scanner(System.in);
int age;
int leapdays;
System.out.print("enter birthday (in english): ");
birthday = kb.nextLine();
Scanner readBday = new Scanner(birthday);
month = readBday.next();
String dateString = readBday.next();
dateString = dateString.substring(0,dateString.length()-1);
date = Integer.parseInt(dateString);
/* our logic was flawed here - leap year status applies to 2016, not to the birth year
however, we can use this code if we write a more general version of the program
year = readBday.nextInt();
if ((year % 4 == 0 && year %100 != 0) || year %400 == 0)
leapdays = 29; // is a leap year
else leapdays = 28; // not a leap year
*/
leapdays = 28; // 2016 is not a leap year
System.out.println("you entered: " + month + " "
+ date + ", " + year);
if (month.equalsIgnoreCase("january"))
monthNum = 1;
else if (month.equalsIgnoreCase("february"))
monthNum = 2;
else if (month.equalsIgnoreCase("march"))
monthNum = 3;
else if (month.equalsIgnoreCase("april"))
monthNum = 4;
else if (month.equalsIgnoreCase("may"))
monthNum = 5;
else if (month.equalsIgnoreCase("june"))
monthNum = 6;
else if (month.equalsIgnoreCase("july"))
monthNum = 7;
else if (month.equalsIgnoreCase("august"))
monthNum = 8;
else if (month.equalsIgnoreCase("september"))
monthNum = 9;
else if (month.equalsIgnoreCase("october"))
monthNum = 10;
else if (month.equalsIgnoreCase("november"))
monthNum = 11;
else if (month.equalsIgnoreCase("december"))
monthNum = 12;
System.out.println("you entered: " + monthNum + "/"
+ date + "/" + year);
int days = 0;
switch (monthNum) {
case 1: case 3: case 5:
case 7: case 8: case 10: case 12:
days += 31 - date;
break;
case 9: case 4: case 11: days += 30 - date;
break;
case 2: days += leapdays - date;
break;
default:
}
switch (monthNum) {
case 1: days += leapdays;
case 2: days += 31;
case 3: days += 30;
case 4: days += 31;
case 5: days += 30;
case 6: days += 31;
case 7: days += 31;
case 8: days += 30;
case 9: days += 31;
case 10: days += 30;
case 11: days += 31;
default:
}
System.out.print("on 9/30/2016 you will be: ");
age = 2016 - year - 1;
System.out.print(age + " year(s) and " + days + " day(s) old");
}
}
Solution
Date class that represents a date consisting of a year, month, and a day
import java.util.TimeZone;
public class Date {
// constants
private static final int JANUARY = 1;
private static final int FEBRUARY = 2;
private static final int DECEMBER = 12;
private static final int DAYS_PER_WEEK = 7;
private static final int DAYS_PER_YEAR = 365;
private static final int DAYS_PER_LEAP_YEAR = 366;
private static final String[] DAY_NAMES = {"SUNDAY", "MONDAY", "TUESDAY",
"WEDNESDAY", "THURSDAY", "FRIDAY", "SATRDAY"};
private static final int[] DAYS_PER_MONTH = { -1,
// 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
};
// fields
private int year;
private int month;
private int day;
/**
Constructs a new object representing the given year, month, and day.
@throws IllegalArgumentException if month is not between 1 and 12, or if day is not between 1
and the number of days in that month.
*/
public Date(int year, int month, int day) {
this.year = year;
this.month = month;
this.day = day;
if (month < 1 || month > 12 || day < 1 || day > getDaysInMonth()) {
throw new IllegalArgumentException("Invalid day or month: " + toString());
}
}
/** Constructs a new object representing today's date. */
public Date() {
this(2006, july
, 22);
int daysSinceEpoch = (int) ((System.currentTimeMillis() +
TimeZone.getDefault().getRawOffset()) / 1000 / 60 / 60 / 24);
for (int i = 0; i < daysSinceEpoch; i++) {
nextDay();
}
}
/**
Adds the given number of days to this Date.
@throws IllegalArgumentException if days < 0.
*/
public void addDays(int days) {
while (days > getDaysInYear()) {
days -= getDaysInYear();
year++;
}
for (int i = 1; i <= days; i++) {
nextDay();
}
}
/**
Returns whether o refers to a Date object representing the same
year, month, and day as this one.
*/
public boolean equals(Object o) {
Date other = (Date) o;
return day == other.day &&
month == other.month &&
year == other.year;
}
/**
Returns the day represented by this Date object.
@return the day, between 1 and the number of days in this Date's month
(which varies from 28 to 31)
*/
public int getDay() {
return day;
}
/** Returns the number of days in the month represented by the current Date. */
public int getDaysInMonth() {
int result = DAYS_PER_MONTH[month];
if (month == FEBRUARY && isLeapYear()) {
result++;
}
return result;
}
public int getDaysInYear() {
if (isLeapYear()) {
return 366;
} else {
return 365;
}
}
/**
Returns a string such as "Monday" representing what day of the week
this Date fell on.
@return the day as either "Sunday", "Monday", "Tuesday, "Wednesday", "Thursday",
"Friday", or "Satrday"
*/
public String getDayOfWeek() {
int index = 1;
Date temp = new Date(1753, JANUARY, 1);
while (temp != this) {
temp.nextDay();
index = (index + 1) % DAYS_PER_WEEK;
}
return DAY_NAMES[index];
}
/**
Returns the month represented by this Date object.
@return the month, between 1 and 12
*/
public int getMonth() {
return month;
}
/**
Returns the year represented by this Date object.
@return the year
*/
public int getYear() {
return year;
}
/**
Returns whether this Date falls on a leap year.
@return true if in a year divisible by 4 but not by 100 unless by 400
*/
public boolean isLeapYear() {
return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
/**
Advances this Date to the next day.
If necessary, wraps to the next month and/or year.
*/
public void nextDay() {
day++;
if (day > getDaysInMonth()) {
// wrap to next month
month++;
day = 1;
if (month > DECEMBER) {
// wrap to next year
year++;
month = JANUARY;
}
}
}
/**
Returns a String representation of this Date.
@return a String such as "2007/07/26" for July 26, 2007
*/
public String toString() {
return year + "/" + pad(month) + "/" + pad(day);
}
private String pad(int n) {
if (n < 10) {
return "0" + n;
} else {
return "" + n;
}
}
}
/* get a birthday and say how old the person will be on september 29, 2016
*/
import java.util.Scanner;
public class birthday
{
public static void main(String[] args)
{
String birthday, month;
int date, year, monthNum = 0;
Scanner kb = new Scanner(System.in);
int age;
int leapdays;
System.out.print("enter birthday (in english): ");
birthday = kb.nextLine();
Scanner readBday = new Scanner(birthday);
month = readBday.next();
String dateString = readBday.next();
dateString = dateString.substring(0,dateString.length()-1);
date = Integer.parseInt(dateString);
/* our logic was flawed here - leap year status applies to 2016, not to the birth year
however, we can use this code if we write a more general version of the program
year = readBday.nextInt();
if ((year % 4 == 0 && year %100 != 0) || year %400 == 0)
leapdays = 29; // is a leap year
else leapdays = 28; // not a leap year
*/
leapdays = 28; // 2016 is not a leap year
System.out.println("you entered: " + month + " "
+ date + ", " + year);
if (month.equalsIgnoreCase("january"))
monthNum = 1;
else if (month.equalsIgnoreCase("february"))
monthNum = 2;
else if (month.equalsIgnoreCase("march"))
monthNum = 3;
else if (month.equalsIgnoreCase("april"))
monthNum = 4;
else if (month.equalsIgnoreCase("may"))
monthNum = 5;
else if (month.equalsIgnoreCase("june"))
monthNum = 6;
else if (month.equalsIgnoreCase("july"))
monthNum = 7;
else if (month.equalsIgnoreCase("august"))
monthNum = 8;
else if (month.equalsIgnoreCase("september"))
monthNum = 9;
else if (month.equalsIgnoreCase("october"))
monthNum = 10;
else if (month.equalsIgnoreCase("november"))
monthNum = 11;
else if (month.equalsIgnoreCase("december"))
monthNum = 12;
System.out.println("you entered: " + monthNum + "/"
+ date + "/" + year);
int days = 0;
switch (monthNum) {
case 1: case 3: case 5:
case 7: case 8: case 10: case 12:
days += 31 - date;
break;
case 9: case 4: case 11: days += 30 - date;
break;
case 2: days += leapdays - date;
break;
default:
}
switch (monthNum) {
case 1: days += leapdays;
case 2: days += 31;
case 3: days += 30;
case 4: days += 31;
case 5: days += 30;
case 6: days += 31;
case 7: days += 31;
case 8: days += 30;
case 9: days += 31;
case 10: days += 30;
case 11: days += 31;
default:
}
System.out.print("on 9/30/2016 you will be: ");
age = 2016 - year - 1;
System.out.print(age + " year(s) and " + days + " day(s) old");
}
}

Date class that represents a date consisting of a year, month, and a.pdf

  • 1.
    Date class thatrepresents a date consisting of a year, month, and a day import java.util.TimeZone; public class Date { // constants private static final int JANUARY = 1; private static final int FEBRUARY = 2; private static final int DECEMBER = 12; private static final int DAYS_PER_WEEK = 7; private static final int DAYS_PER_YEAR = 365; private static final int DAYS_PER_LEAP_YEAR = 366; private static final String[] DAY_NAMES = {"SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATRDAY"}; private static final int[] DAYS_PER_MONTH = { -1, // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, }; // fields private int year; private int month; private int day; /** Constructs a new object representing the given year, month, and day. @throws IllegalArgumentException if month is not between 1 and 12, or if day is not between 1 and the number of days in that month. */ public Date(int year, int month, int day) { this.year = year; this.month = month; this.day = day; if (month < 1 || month > 12 || day < 1 || day > getDaysInMonth()) { throw new IllegalArgumentException("Invalid day or month: " + toString()); } }
  • 2.
    /** Constructs anew object representing today's date. */ public Date() { this(2006, july , 22); int daysSinceEpoch = (int) ((System.currentTimeMillis() + TimeZone.getDefault().getRawOffset()) / 1000 / 60 / 60 / 24); for (int i = 0; i < daysSinceEpoch; i++) { nextDay(); } } /** Adds the given number of days to this Date. @throws IllegalArgumentException if days < 0. */ public void addDays(int days) { while (days > getDaysInYear()) { days -= getDaysInYear(); year++; } for (int i = 1; i <= days; i++) { nextDay(); } } /** Returns whether o refers to a Date object representing the same year, month, and day as this one. */ public boolean equals(Object o) { Date other = (Date) o; return day == other.day && month == other.month &&
  • 3.
    year == other.year; } /** Returnsthe day represented by this Date object. @return the day, between 1 and the number of days in this Date's month (which varies from 28 to 31) */ public int getDay() { return day; } /** Returns the number of days in the month represented by the current Date. */ public int getDaysInMonth() { int result = DAYS_PER_MONTH[month]; if (month == FEBRUARY && isLeapYear()) { result++; } return result; } public int getDaysInYear() { if (isLeapYear()) { return 366; } else { return 365; } } /** Returns a string such as "Monday" representing what day of the week this Date fell on. @return the day as either "Sunday", "Monday", "Tuesday, "Wednesday", "Thursday", "Friday", or "Satrday" */ public String getDayOfWeek() { int index = 1; Date temp = new Date(1753, JANUARY, 1);
  • 4.
    while (temp !=this) { temp.nextDay(); index = (index + 1) % DAYS_PER_WEEK; } return DAY_NAMES[index]; } /** Returns the month represented by this Date object. @return the month, between 1 and 12 */ public int getMonth() { return month; } /** Returns the year represented by this Date object. @return the year */ public int getYear() { return year; } /** Returns whether this Date falls on a leap year. @return true if in a year divisible by 4 but not by 100 unless by 400 */ public boolean isLeapYear() { return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0); } /** Advances this Date to the next day. If necessary, wraps to the next month and/or year. */
  • 5.
    public void nextDay(){ day++; if (day > getDaysInMonth()) { // wrap to next month month++; day = 1; if (month > DECEMBER) { // wrap to next year year++; month = JANUARY; } } } /** Returns a String representation of this Date. @return a String such as "2007/07/26" for July 26, 2007 */ public String toString() { return year + "/" + pad(month) + "/" + pad(day); } private String pad(int n) { if (n < 10) { return "0" + n; } else { return "" + n; } } } /* get a birthday and say how old the person will be on september 29, 2016 */ import java.util.Scanner; public class birthday {
  • 6.
    public static voidmain(String[] args) { String birthday, month; int date, year, monthNum = 0; Scanner kb = new Scanner(System.in); int age; int leapdays; System.out.print("enter birthday (in english): "); birthday = kb.nextLine(); Scanner readBday = new Scanner(birthday); month = readBday.next(); String dateString = readBday.next(); dateString = dateString.substring(0,dateString.length()-1); date = Integer.parseInt(dateString); /* our logic was flawed here - leap year status applies to 2016, not to the birth year however, we can use this code if we write a more general version of the program year = readBday.nextInt(); if ((year % 4 == 0 && year %100 != 0) || year %400 == 0) leapdays = 29; // is a leap year else leapdays = 28; // not a leap year */ leapdays = 28; // 2016 is not a leap year System.out.println("you entered: " + month + " " + date + ", " + year); if (month.equalsIgnoreCase("january")) monthNum = 1; else if (month.equalsIgnoreCase("february")) monthNum = 2; else if (month.equalsIgnoreCase("march")) monthNum = 3;
  • 7.
    else if (month.equalsIgnoreCase("april")) monthNum= 4; else if (month.equalsIgnoreCase("may")) monthNum = 5; else if (month.equalsIgnoreCase("june")) monthNum = 6; else if (month.equalsIgnoreCase("july")) monthNum = 7; else if (month.equalsIgnoreCase("august")) monthNum = 8; else if (month.equalsIgnoreCase("september")) monthNum = 9; else if (month.equalsIgnoreCase("october")) monthNum = 10; else if (month.equalsIgnoreCase("november")) monthNum = 11; else if (month.equalsIgnoreCase("december")) monthNum = 12; System.out.println("you entered: " + monthNum + "/" + date + "/" + year); int days = 0; switch (monthNum) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: days += 31 - date; break; case 9: case 4: case 11: days += 30 - date; break; case 2: days += leapdays - date; break; default: }
  • 8.
    switch (monthNum) { case1: days += leapdays; case 2: days += 31; case 3: days += 30; case 4: days += 31; case 5: days += 30; case 6: days += 31; case 7: days += 31; case 8: days += 30; case 9: days += 31; case 10: days += 30; case 11: days += 31; default: } System.out.print("on 9/30/2016 you will be: "); age = 2016 - year - 1; System.out.print(age + " year(s) and " + days + " day(s) old"); } } Solution Date class that represents a date consisting of a year, month, and a day import java.util.TimeZone; public class Date { // constants private static final int JANUARY = 1; private static final int FEBRUARY = 2; private static final int DECEMBER = 12; private static final int DAYS_PER_WEEK = 7; private static final int DAYS_PER_YEAR = 365; private static final int DAYS_PER_LEAP_YEAR = 366; private static final String[] DAY_NAMES = {"SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATRDAY"}; private static final int[] DAYS_PER_MONTH = { -1,
  • 9.
    // 1, 2,3, 4, 5, 6, 7, 8, 9, 10, 11, 12 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, }; // fields private int year; private int month; private int day; /** Constructs a new object representing the given year, month, and day. @throws IllegalArgumentException if month is not between 1 and 12, or if day is not between 1 and the number of days in that month. */ public Date(int year, int month, int day) { this.year = year; this.month = month; this.day = day; if (month < 1 || month > 12 || day < 1 || day > getDaysInMonth()) { throw new IllegalArgumentException("Invalid day or month: " + toString()); } } /** Constructs a new object representing today's date. */ public Date() { this(2006, july , 22); int daysSinceEpoch = (int) ((System.currentTimeMillis() + TimeZone.getDefault().getRawOffset()) / 1000 / 60 / 60 / 24); for (int i = 0; i < daysSinceEpoch; i++) { nextDay(); } } /**
  • 10.
    Adds the givennumber of days to this Date. @throws IllegalArgumentException if days < 0. */ public void addDays(int days) { while (days > getDaysInYear()) { days -= getDaysInYear(); year++; } for (int i = 1; i <= days; i++) { nextDay(); } } /** Returns whether o refers to a Date object representing the same year, month, and day as this one. */ public boolean equals(Object o) { Date other = (Date) o; return day == other.day && month == other.month && year == other.year; } /** Returns the day represented by this Date object. @return the day, between 1 and the number of days in this Date's month (which varies from 28 to 31) */ public int getDay() { return day; } /** Returns the number of days in the month represented by the current Date. */ public int getDaysInMonth() { int result = DAYS_PER_MONTH[month];
  • 11.
    if (month ==FEBRUARY && isLeapYear()) { result++; } return result; } public int getDaysInYear() { if (isLeapYear()) { return 366; } else { return 365; } } /** Returns a string such as "Monday" representing what day of the week this Date fell on. @return the day as either "Sunday", "Monday", "Tuesday, "Wednesday", "Thursday", "Friday", or "Satrday" */ public String getDayOfWeek() { int index = 1; Date temp = new Date(1753, JANUARY, 1); while (temp != this) { temp.nextDay(); index = (index + 1) % DAYS_PER_WEEK; } return DAY_NAMES[index]; } /** Returns the month represented by this Date object. @return the month, between 1 and 12 */ public int getMonth() { return month;
  • 12.
    } /** Returns the yearrepresented by this Date object. @return the year */ public int getYear() { return year; } /** Returns whether this Date falls on a leap year. @return true if in a year divisible by 4 but not by 100 unless by 400 */ public boolean isLeapYear() { return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0); } /** Advances this Date to the next day. If necessary, wraps to the next month and/or year. */ public void nextDay() { day++; if (day > getDaysInMonth()) { // wrap to next month month++; day = 1; if (month > DECEMBER) { // wrap to next year year++; month = JANUARY; } } }
  • 13.
    /** Returns a Stringrepresentation of this Date. @return a String such as "2007/07/26" for July 26, 2007 */ public String toString() { return year + "/" + pad(month) + "/" + pad(day); } private String pad(int n) { if (n < 10) { return "0" + n; } else { return "" + n; } } } /* get a birthday and say how old the person will be on september 29, 2016 */ import java.util.Scanner; public class birthday { public static void main(String[] args) { String birthday, month; int date, year, monthNum = 0; Scanner kb = new Scanner(System.in); int age; int leapdays; System.out.print("enter birthday (in english): "); birthday = kb.nextLine(); Scanner readBday = new Scanner(birthday); month = readBday.next();
  • 14.
    String dateString =readBday.next(); dateString = dateString.substring(0,dateString.length()-1); date = Integer.parseInt(dateString); /* our logic was flawed here - leap year status applies to 2016, not to the birth year however, we can use this code if we write a more general version of the program year = readBday.nextInt(); if ((year % 4 == 0 && year %100 != 0) || year %400 == 0) leapdays = 29; // is a leap year else leapdays = 28; // not a leap year */ leapdays = 28; // 2016 is not a leap year System.out.println("you entered: " + month + " " + date + ", " + year); if (month.equalsIgnoreCase("january")) monthNum = 1; else if (month.equalsIgnoreCase("february")) monthNum = 2; else if (month.equalsIgnoreCase("march")) monthNum = 3; else if (month.equalsIgnoreCase("april")) monthNum = 4; else if (month.equalsIgnoreCase("may")) monthNum = 5; else if (month.equalsIgnoreCase("june")) monthNum = 6; else if (month.equalsIgnoreCase("july")) monthNum = 7; else if (month.equalsIgnoreCase("august")) monthNum = 8; else if (month.equalsIgnoreCase("september")) monthNum = 9; else if (month.equalsIgnoreCase("october")) monthNum = 10;
  • 15.
    else if (month.equalsIgnoreCase("november")) monthNum= 11; else if (month.equalsIgnoreCase("december")) monthNum = 12; System.out.println("you entered: " + monthNum + "/" + date + "/" + year); int days = 0; switch (monthNum) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: days += 31 - date; break; case 9: case 4: case 11: days += 30 - date; break; case 2: days += leapdays - date; break; default: } switch (monthNum) { case 1: days += leapdays; case 2: days += 31; case 3: days += 30; case 4: days += 31; case 5: days += 30; case 6: days += 31; case 7: days += 31; case 8: days += 30; case 9: days += 31; case 10: days += 30; case 11: days += 31; default: }
  • 16.
    System.out.print("on 9/30/2016 youwill be: "); age = 2016 - year - 1; System.out.print(age + " year(s) and " + days + " day(s) old"); } }