Partial
2006-10-18, 22:56
I am working on a program for my object-oriented programming class. We're writing our code in Java.
I'm working on a program that is involving a list of dates. The class we're working in is called TDate, since Java has a built-in date class. I have two dates of type TDate d1 and d2. I need to be able to figure out how many integer days are in between the two dates.
I have greaterThan and lessThan functions within the class which let me know which date is bigger and which is smaller. The problem is I am not sure how I would go about keeping an active count on the dates because the months really throw things off.
For example,
11/25/2002 is considered "less than" 12/15/2003, yet if I were to loop through it the months would clearly not reflect this.
What I do have is a function that keeps track of the last day of the month for me. I am assuming I will need this to validate leap years and such.
public int lastDayOfMonth()
{
switch ( month )
{
case APR : case JUN : case SEP : case NOV :
return 30;
case FEB :
if( year % 400 == 0 || year % 4 == 0 && year % 100 != 0 )
return 29;
return 28;
default:
return 31;
}
}
So, any thoughts? I am rather confused and the program is due at 8:00am Central time Friday morning, so i've got a little time but would rather just get this done.
I'm working on a program that is involving a list of dates. The class we're working in is called TDate, since Java has a built-in date class. I have two dates of type TDate d1 and d2. I need to be able to figure out how many integer days are in between the two dates.
I have greaterThan and lessThan functions within the class which let me know which date is bigger and which is smaller. The problem is I am not sure how I would go about keeping an active count on the dates because the months really throw things off.
For example,
11/25/2002 is considered "less than" 12/15/2003, yet if I were to loop through it the months would clearly not reflect this.
What I do have is a function that keeps track of the last day of the month for me. I am assuming I will need this to validate leap years and such.
public int lastDayOfMonth()
{
switch ( month )
{
case APR : case JUN : case SEP : case NOV :
return 30;
case FEB :
if( year % 400 == 0 || year % 4 == 0 && year % 100 != 0 )
return 29;
return 28;
default:
return 31;
}
}
So, any thoughts? I am rather confused and the program is due at 8:00am Central time Friday morning, so i've got a little time but would rather just get this done.