import java.util.Objects; public class Date implements Comparable { private int year; private Month month; private int day; public Date(int year, Month month, int day) { this.year = year; this.month = month; this.day = day; } @Override public boolean equals(Object obj) { if (obj == null) return false; if (!getClass().equals(obj.getClass())) return false; Date d = (Date)obj; return year == d.year && month.equals(d.month) && day == d.day; } public int compareTo(Date other) { int yearDiff = year - other.year; if (yearDiff != 0) return yearDiff; int monthDiff = month.compareTo(other.month); if (monthDiff != 0) return monthDiff; return day - other.day; } @Override public int hashCode() { return Objects.hash(year, month, day); } public String toString() { return String.format("%d %s %d", day, month, year); } }