The Question:
"create a method called compare, which takes a parameter of type Date and calculates the number of days between the date of the current object and the input object."
public class Date {
int year;
int month;
int day;
void print() {
System.out.printf("Date: %d/%d/%d", this.month, this.day, this.year);
}
void addDays(int n) {
int[] month = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int i = this.month - 1;
int day = this.day + n;
while (day > month[i]) {
day -= month[i];
if (this.month == 12) {
this.year++;
this.month = 0;
i = -1;
}
this.month++;
i++;
}
this.day = 0;
this.day += day;
}
int compare(Date d1) {
return 0;
}
}
This is what I currently have and I was wondering how would I implement this method I've tried messing around with the my method add days but I couldn't quite figure it out.
Again, I've tried messing around with addDays and adding parameter so that the method the object is calling must always be older than the one being compared but I get quite lost. Any advice would help.