Java
This commit is contained in:
BIN
APL2.1/TP05/Date/Date.class
Normal file
BIN
APL2.1/TP05/Date/Date.class
Normal file
Binary file not shown.
6
APL2.1/TP05/Date/Date.java
Normal file
6
APL2.1/TP05/Date/Date.java
Normal 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());
|
||||
}
|
||||
}
|
||||
BIN
APL2.1/TP05/Date/MyDate.class
Normal file
BIN
APL2.1/TP05/Date/MyDate.class
Normal file
Binary file not shown.
33
APL2.1/TP05/Date/MyDate.java
Normal file
33
APL2.1/TP05/Date/MyDate.java
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user