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

Binary file not shown.

View File

@@ -0,0 +1,37 @@
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 boolean isEqual(MyDate date) {
return (this.year == date.year && this.month == date.month && this.day == date.day);
}
public MyDate(int y, int m, int d) {
this.year = y;
this.month = m;
this.day = d;
}
}

Binary file not shown.

View File

@@ -0,0 +1,31 @@
public class MyPeriod {
private int length;
public String toString() {
return "Periode : " + length + " jour" + (length > 1 ? "s" : "");
}
public void addDay() {
this.length += 1;
}
public MyPeriod(MyDate date1, MyDate date2) {
if (date1.isEqual(date2)) {
this.length = 0;
return;
}
//Très dangereux et inefficace, ne faites pas ca svp.
while (!date1.isEqual(date2)) {
date1 = date1.tomorrow();
length++;
}
}
public MyPeriod(int length) {
this.length = length;
}
}

Binary file not shown.

View File

@@ -0,0 +1,9 @@
public class Periode {
public static void main(String[] args) {
MyDate date1 = new MyDate(2002, 05, 29);
MyDate date2 = new MyDate(2022, 05, 29);
MyPeriod p = new MyPeriod(date1, date2);
System.out.println(p.toString());
}
}