class Date{
int day, month, year, dayOfweek;
public static int[] daysInMonth ={31,28,30,30,31,30,31,31,30,31,30,31};
public static String[] MonName = {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
public static String[] dayName = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday"};
public static Boolean isLeap(int year ){
if(year % 400 == 0)
return true;
if(year % 100 == 0 || year % 4 !=0)
return false;
return true;
}
Date(int d, int m, int y){
day = d-1;
month = m-1;
year = y;
dayOfweek=-1;
}
Date(int d, int m, int y, int w){
day = d-1;
month = m-1;
year = y;
dayOfweek =w;
}
public void next(){
if( isLeap( year ))
daysInMonth[1] = 29;
else
daysInMonth[1] = 28;
day++;
if(day == daysInMonth[month]){
day = 0;
month++;
}
if (month == 12){
month = 1;
year++;
}
dayOfweek++;
dayOfweek%=7;
}
public void print(){
System.out.println(MonName[month] + " " + (day+1) + "is a" + dayName[dayOfweek]);
}
public int compare(Date target){
if( year < target.year )
return 1;
if(year < target.year)
return -1;
if(month < target.month)
return -1;
if(month > target.month)
return -1;
if( day < target.day)
return 1;
if(day > target.day)
return -1;
return 0;
}
}
2007-02-27
03:36:58
·
2 answers
·
asked by
Anonymous