//An instance of this class represents a Gregorian Calendar date // 1582 or later public class CalendarDate { public enum DateFormat { STANDARD, //3 August 2012 US_FORMAT, //Aug 3, 2012 ISO_8601; //2012-08-03 } //Instance (State) Variables private CalendarYear year; //A Calendar year private CalendarMonth month; //A Calendar month private CalendarDay day; //1 .. 28/29/30/31 private DateFormat format; //Display format //Constructor public CalendarDate(int day, int month, int year) { this.format = DateFormat.STANDARD; } //Accessors //Mutator public void setFormat(CalendarDate.DateFormat format) { this.format = format; } //Override //The format of the returned image of this CalendarDate //is determined by the value of instance variable format public String toString() { switch ( this.format ) { case STANDARD : case US_FORMAT : case ISO_8601 : default : return "07/01/2015"; } } //Helper private static String twoDigits(int number) { return (number < 10 ? "0" : "") + number; } //Compare this CalendarDate with an other CalendarDate // Returns 0 if the dates are identical // any negative number if this precedes other // any positive number if this succeeds other public int compareTo(CalendarDate other) { return 0; } //Returns the ordinal (day-number)of this CalendarDate // Jan 1 has ordinal 1, Jan 31 has ordinal 31 // Feb 1 has ordinal 32, Feb 28 has ordinal 39 // Mar 1 has ordinal 40 in an ordinary year, // 41 in a leap year // Dec 31 has ordinal 365 in an ordinary year, // 366 in a leap year public int ordinal() { return 0; } //Return the anniversary date in another year of this CalendarDate // Example, the 2015 anniversary date of 05/18/1995 is 05/18/2015 // @param year: the anniversary year public CalendarDate anniversary(CalendarYear year) { return this; } }