class DateTest { public static void main(String[] args) { Date d1 = new Date(15, 6, 2005); Date d2 = new Date(2005); Date d3 = new Date(d1); System.out.println("The first day is " + d1); System.out.println("Another day is " + d2); System.out.println("A copy of the first day is " + d3); String climate = d1.expectedTemperature(); System.out.println("The climate on " + d1 + " is " + climate); Date d4 = new Date(30, 5, 2008); Date d5 = d4.nextDay(); Date d6 = d4.nextDay().nextDay(); System.out.println("Today is " + d4); System.out.println("Tomorrow is " + d5); System.out.println("The day after that is " + d6); Date d7 = new Date(15, 9, 2005); Date d8 = new Date(8, 12, 2005); Date d9 = Date.later(d7, d8); System.out.println("The later date is " + d8); Date d10 = new Date(21, 8, 2005); Date d11 = new Date(25, 8, 2007); System.out.println("sameMonth is " + d10.sameMonth(d11)); Date d12 = new Date(30, 6, 2005); Date d13 = new Date(30, 6, 2005); Date d14 = d13; System.out.println("d12 == d13 is " + (d12 == d13) + " (expect false)"); System.out.println("d13 == d14 is " + (d13 == d14) + " (expect true)"); System.out.println("d12 instanceof Date is " + (d12 instanceof Date) + " (expect true)"); d12 = null; System.out.println("After setting to null, " + "d12 instanceof Date is " + (d12 instanceof Date)); } } // end of class DateTest class Date { int day; int month; int year; static int[] monthDays = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; Date(int d, int m, int y) { // constructor day = d; month = m; year = y; } Date(int y) { // another constructor year = y; } Date(Date d) { // copy constructor day = d.day; month = d.month; year = d.year; } public String toString() { return day + "/" + month + "/" + year; } // end of toString() String expectedTemperature() { if (month >= 5 && month <= 9) return "warm"; else return "cold"; } // end of expectedTemperature() Date nextDay() { Date tomorrow = new Date(day + 1, month, year); if (tomorrow.day > monthDays[month]) { tomorrow.month++; tomorrow.day = 1; } if (tomorrow.month > 12) { tomorrow.year++; tomorrow.month = 1; } return tomorrow; } // end of nextDay() boolean sameMonth(Date other) { if (this.month == other.month) return true; else return false; } // end of sameMonth() static Date later(Date d1, Date d2) { if (d1.year > d2.year) return d1; else if (d1.year < d2.year) return d2; else if (d1.month > d2.month) return d1; else if (d1.month < d2.month) return d2; else if (d1.day > d2.day) return d1; else return d2; } // end of later() } // end of class Date