This commit is contained in:
2022-02-15 11:26:26 +01:00
parent f24050cb7e
commit 975abd0e19
26 changed files with 15966 additions and 0 deletions

BIN
APL2.1/TP05/Date/Date.class Normal file

Binary file not shown.

View File

@@ -0,0 +1,6 @@
public class Date {
public static void main(String[] args) {
MyDate date = new MyDate(2002, 05, 29);
System.out.println(date.toString());
}
}

Binary file not shown.

View File

@@ -0,0 +1,33 @@
public class MyDate {
private int year;
private int month;
private int day;
private int[] monthDurations = new int[] {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
public String toString() {
return String.format("%04d-%02d-%02d", year, month, day);
}
public MyDate tomorrow() {
MyDate newDate = new MyDate(this.year, this.month, this.day+1);
if (newDate.day > monthDurations[newDate.month-1]) {
newDate.day = 1;
newDate.month += 1;
}
if (newDate.month > 12) {
newDate.month = 1;
newDate.year += 1;
}
return newDate;
}
public MyDate(int y, int m, int d) {
this.year = y;
this.month = m;
this.day = d;
}
}