/** * A version of GTDate that is specialized to handle European style dates */ public class EuropeanDate extends GTDate { /** * Constructor * @param day * @param month * @param year */ public EuropeanDate(int day, int month, int year) { super(month, day, year); // just call teh GTDate constructor } /** * @return date in european style */ public String toString() { return "€"+day + "/" + month + "/" + year; } /** * Handle string in European form * @param a string -- presumably holding a date */ public boolean equals(String oString) { System.out.println("Equals String"); if (oString.length()<7) { return false; } //return oString.equals(toString()); // works sometimes but fragile // so break the string up into components // first strip off the € if it is there if (oString.charAt(0)=='€') { oString = oString.substring(1); } 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]); //System.out.println(m + "." + d + "." + y); // should I check for american?? return y == year && m == month && d == day; } catch (Exception ee) { return false; } } else { return false; } } public static void main(String[] args) { GTDate d1 = new GTDate(1, 2, 10); EuropeanDate d2 = new EuropeanDate(2, 1, 10); System.out.println(d1 + " equals? " + d2 + " " + d1.equals(d2)); System.out.println(d2 + " equals? " + d1 + " " + d2.equals(d1)); String s1 = "€1/2/10"; System.out.println(d1 + " equals? " + s1 + " " + d2.equals(s1)); System.out.println(d1 + " equals? " + s1 + " " + d1.equals(s1)); System.out.println(s1 + " equals? " + d2 + " " + s1.equals(d1)); System.out.println(s1 + " equals? " + d2 + " " + s1.equals(d2.toString())); } }