Here is what I have for Date
public class Date
{
//Declare variables
private int month;
private int day;
private int year;
public Date(int m, int d, int y)
{
int year = 0;
int day = 0;
int month = 2009;
}
public int checkDay( int testDay)
{
int[]daysOfMonth = {0,31,28,31,30,31,30,31,31,30,31,30,31};
if(testDay > 0 && testDay <= daysOfMonth[month])
return testDay;
else if (month == 2)
//else if(month == testDay != 29 &&(year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)))
return testDay;
else if(month ==2)
{
boolean isleap = true;
if(year % 4 != 0)
isleap = false;
else if((year % 100 == 0) && (year % 400 == 0))
isleap = true;
if((isleap == true) && (day <= 29))
return day;
else if((isleap == false) && (day <= 28))
return day;
System.out.println("Day" + testDay + "invalid.Set to day 1.");
return 1;}
return day;
}
public int nextDay()
{
int testDay = day + 1;
if( checkDay(testDay) == testDay)
day = testDay;
else
{
day = 1;
nextMonth();
}
return day;
}
public int nextMonth()
{
if (12 == month)
year++;
return month = 1;
}
}
And for DateTest
public class DateTest {
public static void main(String[] args)
{
Date date = new Date(0, 0, 0);
Date date2 = new Date(11,27,1988);
for (int counter = 0; counter < 40; counter++)
{
date2.nextDay();
System.out.println("Incremented Date:" + date2.toString());
}
}
}
Thsi is my output:
Incremented Date:Date@10b62c9 Incremented Date:Date@10b62c9 Incremented Date:Date@10b62c9 Incremented Date:Date@10b62c9 Incremented Date:Date@10b62c9 Incremented Date:Date@10b62c9 Incremented Date:Date@10b62c9 Incremented Date:Date@10b62c9 Incremented Date:Date@10b62c9 Incremented Date:Date@10b62c9 Incremented Date:Date@10b62c9
And this is what my output is supposed to be:
Checking increment Date object constructor for date 11/27/1988 Incremented Date: 11/28/1988 Incremented Date: 11/29/1988 Incremented Date: 11/30/1988 Day 31 invalid. Set to day 1. Incremented Date: 12/1/1988 ... ... Incremented Date: 12/31/1988 Day 32 invalid. Set to day 1. Incremented Date: 1/1/1989 ... ...
I'm only required to loop through 40 times.
I'm sure that there is more than a couple problems with my code but I would appreciate help with any of it. Thanks!
This post has been edited by Vanessa6: 18 September 2009 - 06:05 PM

New Topic/Question
Reply



MultiQuote









|