package username.dates; /** * An implementation of dates that stores dates with the month and * day of month as separate integer fields. * * @author Samuel A. Rebelsky * @version 1.0 of September 2005 */ public class MonthDay implements SimpleDate { // +--------+------------------------------------------------------------ // | Fields | // +--------+ /** The month. */ int month; /** The day of the month. */ int day; // +--------------+------------------------------------------------------ // | Constructors | // +--------------+ /** * Create the date "_month _day". */ public MonthDay(int _month, int _day) { this.month = _month; this.day = _day; } // MonthDay(int,int) // +---------+----------------------------------------------------------- // | Methods | // +---------+ /** * Determine this date's position in the year. January 1 is the * 1st day of the year, December 31st is the 365th day of the year. */ public int dayOfYear() { int daysBefore = 0; // The number of days before the end of the month. for (int month = 0; month < this.month; month++) { daysBefore = daysBefore + DateHelper.daysInMonth(month); } // for return daysBefore + this.day; } // dayOfYear() /** * Determine the month. Returns a value between 1 and 12. */ public int month() { return this.month; } // month() /** * Determine the day within the month. */ public int day() { return this.day; } // day() /** * Convert to a string of the form MONTH DAY, such as January 10 * or June 17. */ public String toString() { return DateHelper.nameOfMonth(this.month) + " " + this.day; } // toString() } // class MonthDay