// Programmer: Rance Cleaveland // Date: 21 Sept. 2006 // // This class implements simple operations on dates. public class Date { public int day = 1; // Day part of date public int month = 1; // Month part of date public int year = 1900; // Year part of date public String separator = "/"; // Separator used in printing public String note; // Used for comment on date. // "print" prints date in US format. public void print () { System.out.print (month + separator + day + separator + year); } // "println" prints the date followed by a carriage return public void println () { print (); // Calls print method above! System.out.println (); } // "incrementYear" increments the year. public void incrementYear () { year++; } // "incrementMonth" increments the month. public void incrementMonth () { if (month < 12) month++; else { month = 1; year++; } } // "setYear" allows the year to be set to a give value public void setYear (int newYear) { year = newYear; } // "isValentinesDay" returns true if the date is Valentines Day public boolean isValentinesDay () { return ((month == 2) && (day == 14)); } // "isBefore" returns true if the date is before the inputted date public boolean isBefore (Date d) { if (year < d.year) return true; else if (year == d.year) { if (month < d.month) return true; else if ( (month == d.month) && (day < d.day) ) return true; else return false; } else return false; } }