0
class Date { 

   private int day, month, year; // the date
    
   Date(int d, int m, int y){
	   day = d; month = m; year = y;
   }

   Date(){ };

   void get() {
	   day = Console.readInt(); month = Console.readInt(); year = Console.readInt();
   }

  void put(){
	  System.out.println(day + "/" + month + "/" + year);

  private int elapsedDays() {
  // The number of days elapsed from 1/1/1900 to this date
    int days = (year-1900)*365+(year-1901)/4; 
    int k = 1;
    while (k<month) {
	int daysInMonth;
	if (k==9||k==4||k==6||k==11) 
		daysInMonth = 30;
	else if (k==2) {
		if (year%4==0 && year!=1900) daysInMonth = 29;
		else daysInMonth = 28;
	}
	else daysInMonth = 31;
      days = days + daysInMonth; 
      k++; 
    }
    return days + day;
  }
   
   boolean postDates(Date d) {
	  // Does this date occur on or after d?
    .....
  }
}

my mind has gone completely blank with the boolean method postDates would appreciate a bit of help!!

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by Ezzaral
0

Thanks James that method works but I think we have to use the elapsedDays method to solve it. I can't seem to get it to work with the boolean method.

0

OK, you didn't say that before.
If you use elapsedDays then it's really easy. Whichever date has the highest elapsedDays is the later of the two.

0
boolean postDates(Date d) {
	   Date e = new Date();
	   return (e.elapsedDays() > d.elapsedDays());
}

I know theirs an easy answer I just can't seem to get it working

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.