//I am having troubles trying to figure out how to compare two dates in my class. In my DateClient, I created two dates, but don't know how to use them. If you're wondering I'm creating a date class to compare the dates to find how //many days ago was that date and on what day was it.
//Date d1 = new Date(2015,10,20);
//Date d2 = new Date(2000,3,12);
public class Date {
private int year;
private int day;
private int month;
public Date(int year, int month, int day){
// this.year = year;
// this.month = month;
// this.day = day;
year=0;
month=0;
day=0;
}
public int getYear(){
return year;
}
public void setYear(){
this.year=year;
}
public int getMonth(){
return month;
}
public void setMonth(){
this.month=month;
}
public int getDay(){
return day;
}
public void setDay(){
this.day=day;
}
public String toString(){
return (year+"/"+month+"/"+day);
}
public boolean equals(Date D){
boolean Same = false;
if (day==this.day && month==this.month && year==this.year){
Same = true;
} else Same = false;
return Same;
}
public boolean isLeapYear(int year){
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0){
return true;
} else return false;
}
public void nextDay(){
day++;
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 && day == 32){
month++;
day = 1;
} else if (month == 4 || month == 6 || month == 9 || month == 11 && day == 31){
month++;
day = 1;
} else if (month == 12 && day == 32){
month = 1;
year++;
day = 1;
} else if (month == 2){
if (isLeapYear(year) == true && day == 30){
day = 1;
} else if (isLeapYear(year) == false && day == 29){
day = 1;
}
}
}
public int advanceTo(Date endDay){
int countDays = 0;
while ( != endDay){
countDay++;
}
}
}
}
<pre lang="java"><pre lang="java"><pre lang="java"><pre lang="java">