33 lines
781 B
Java
33 lines
781 B
Java
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;
|
|
}
|
|
} |