public class MyDate{
private int year;
private int month;
private int day;
public MyDate(int year, int month, int day){
this.year = year;
this.month = month;
this.day = day;
}
public MyDate nextDay(){
int newDay = day + 1;
int newMonth = month;
int newYear = year;
if(newDay > 30){
newMonth ++;
newDay = 1;
}
if(newMonth > 12){
newYear ++;
newMonth = 1;
}
MyDate newDate =
new MyDate(newYear, newMonth, newDay);
return newDate;
}
public int getYear(){
return year;
}
public int getMonth(){
return month;
}
public int getDay(){
return day;
}
}
package ch04;
public class DateTest{
public static void main(String[] args){
MyDate oldDate = new MyDate(2005, 12, 30);
MyDate newDate = oldDate.nextDay();
System.out.println(newDate.getYear());
System.out.println(newDate.getMonth());
System.out.println(newDate.getDay());
}
}