// Programmer: Rance Cleaveland // Date: 25 Sept. 2006 // // This class implements simple operations on dates. public class DateNoPrint { 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. // Default constructor DateNoPrint () { year = 2000; } // Another constructor DateNoPrint (int newDay, int newMonth, int newYear){ day = newDay; month = newMonth; year = newYear; } // The method for converting dates to strings public String toString () { return (month + separator + day + separator + year); } // "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; } // "setMonth" allows the month to be set; an error is reported // if the month is invalid public void setMonth (int newMonth) { if ((1 <= newMonth) && (newMonth <= 12)) month = newMonth; else System.out.println ("Bad argument to setMonth: " + newMonth); } // "getDay" returns the day public int getDay () { return day; } // "getMonth" returns the month public int getMonth () { return month; } // "getYear" returns the year public int getYear () { return year; } // "isValentinesDay" returns true if the date is Valentines Day public boolean isValentinesDay () { return ((month == 2) && (day == 14)); } // "equals" computes an equality function on dates public boolean equals (DateNoPrint d) { return (day == d.day && month == d.month && year == d.year); } // "isBefore" returns true if the date is before the inputted date public boolean isBefore (DateNoPrint 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; } }