Subato

Date (Wochentag, Muttertag)

class Date{
  int day;
  int month;
  int year;

  Date(int day, int month, int year){
    assert month>0;
    assert month<13;
    assert day>0;
    assert day<32;

    this.day = day;
    this.month = month;
    this.year = year;
  }

  int dayOfWeek(){
    //Schrittweise Lösung über die Einzelziffern
    /*
    int tz = day%7;
    int[] monatsziffern = {0,3,3,6,1,4,6,2,5,0,3,5};
    int mz = monatsziffern[month-1];
    int jz = year%100; 
    int jahresziffer = (jz+jz/4)%7;
    int jh = year/100;
    int jahrhundertziffer = (3 - jh%4)*2;
    int schaltjahreskorrektur
      = (isEarlierThan(new Date(1,3,year))&&isLeapYear())?6:0;
      return (tz+mz+jahresziffer+jahrhundertziffer+schaltjahreskorrektur)%7;
    */
    //Lösung mit Einsetzen direkt in die Formel
    int y = (month < 3)? (year - 1):year;
    var result = (day + (26 * ((month + 9) % 12 + 1) - 2)/10
                    + y % 100
                    + (y % 100 / 4)
                    + (y / 400) - 2 * (y / 100) 
                  ) % 7 ;
    return result<0?result+7:result; 
  }

  Date mothersDay() {
    int wd = new Date(1, 5, year).dayOfWeek();
    return new Date(wd == 0 ? 8 : (15 - wd), 5, year);
  }

  boolean isEarlierThan(Date that){
    return
         year<that.year
      || (year==that.year && month<that.month)
      || (year==that.year && month==that.month && day<that.day);
  }
  
  boolean isLaterThan(Date that){
    return that.isEarlierThan(this);
  }
  
  boolean isSameDate(Date that){
    return year==that.year &&month==that.month&&day==that.day;
  }
  public String toString(){
    return ""+day+"."+month+"."+year;
  }
  
  boolean isLeapYear(){
    return year%400==0
         ||(year%4==0 && year%100!=0);
  }
  int getAbsoluteDaysInYear(){
    return isLeapYear()?366:365;
  }
  public static void main(String[] args){
    Date d = new Date(30,11,2018);
    System.out.println(d);
  }
}