/** * A class to implement holding the date. * * @author ggtowell * Created: Dec 2023 */ public class GTDate { // the month int month; // the day int day; // the year int year; /** * Create a date Object * @param mt the month * @param dt the day * @param yr the year */ public GTDate(int mt, int dt, int yr) { month = mt; day = dt; year = yr; } /** * @Override indicates that this function is defined in a class that the * current function inherits from * Generate a string representation for the class */ @Override public String toString() { return month + "/" + day + "/" + year; } /** * A long, involved equals method covering lots of possibilities. * @return true is the dates are the same */ @Override public boolean equals(Object ob) { if (ob instanceof String) { String oString = (String) ob; //return oString.equals(toString()); // works but fragile // break the string up into components String[] ss = oString.split("/"); if (ss.length == 3) { try { int d=Integer.parseInt(ss[0]); int m = Integer.parseInt(ss[1]); int y = Integer.parseInt(ss[2]); return y==year && m==month && d==day; } catch (Exception ee) { return false; } } else { return false; } } if (ob instanceof GTDate) { GTDate gtd = (GTDate) ob; return month == gtd.month && day == gtd.day && year == gtd.year; } return super.equals(ob); } public void setDay(int dt) { day = dt; } }