package dk.itu.oop.lecture8; class DateHelper { static final int[] daysInMonth={31,28,31,30,31,30,31,31,30,31,30,31,}; public static class IllegalDateArguments extends IllegalArgumentsException{} public static class IllegalDaysAfterArguments extends IllegalDateArguments{ public final int days; public final Date d; public IllegalDaysAfterArguments(int days,Date d){ this.days = d; this.d = d; } } public static class IllegalDaysBetweenArguments extends IllegalDateArguments{ public final Date d1; public final Date d2; public IllegalDaysBetweenArguments(Date d1,Date d2){ this.d1 = d1; this.d2 = d2; } } public static Date daysAfter(int days, Date d){ if (days <= 0) throw new IllegalDaysAfterArguments(days, d); int day = d.getDay()+days; int month = d.getMonth(); int year = d.getYear(); while (day > MyDate.daysInMonth[month]){ days = days - daysInMonth[month]; month ++; if (month>12) { year++; month = 1; } } return new MyDate(year, month, day); } public static int daysBetween(Date d1, Date d2){ int diff = (d2.getYear() - d1.getYear())*365; if (diff <= 0 ) throw new IllegalDaysBetweenArguments(d1,d2); int dayInYear1 = 0; for (int i=1; i