Date conversion program

Hi. Im having trouble with converting the number of days between two dates in my program. Here is the code. Its the birthday and conversion void that im having problems with. The conversion converts the date to the number of days between the current date and 1/11900. The birthday does the same but with 30/12/1987. Please help me sort this out.

publicclass Date{

/**

* Date project

*

* @author Kurt

* @version 1.0, Feb 2007

*/

int m;// Months

int y;// Years

int numDays = 0;//This will store the value of the number of days in a month.

int d;// Days

int daysOver = 0;

public Date(){

d=27;// Fills the 3 ints 1/1/07 initially.

m=2;// This is to avoid having to press add year 2007 times to get to the current year.

y=2007;

switch (m){// Switch statement to declare how many days are in a month.

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

numDays = 31;

break;

case 4:

case 6:

case 9:

case 11:

numDays = 30;

break;

case 2:

if ( ((y % 4 == 0) && !(y % 100 == 0))// This section sets up the leap year scenario.

|| (y % 400 == 0) )// Meaning that the Feb has:

numDays = 29;// 29 days on a leap year or

else

numDays = 28;// 28 days normally.

break;

default:

System.out.println("Invalid month.");//Stops the month from going out of the 12 months.

break;

}

}

publicvoid tomorrow(){

d++;// Adds a day, day = day + 1.

if (d > numDays){// Goes forward a month if it reaching the end of the month.

m++;

d = 1;

}

}

publicvoid yesterday(){

d--;// Subtracts a day, day = day - 1.

if (d < numDays){//Goes back a month if the day is bellow 0

m--;

d = numDays;

}

}

publicvoid addYear(){

y++;// adds a year, year = year + 1.

}

publicvoid subtractYear(){

y--;// Subtracts a year, year = year - 1.

}

publicvoid addMonth(){

m++;// Adds a month, month = month + 1.

if (m>12){// If the month goes past December then it goes to January of the next year

y++;

m = 1;

d = 1;

}

}

publicvoid subtractMonth(){

m--;// Subtracts a month, month = month - 1.

if (m < 12){// If the month goes under January then it goes to December of the previous year

y--;

m=12;

d = numDays;

}

}

publicvoid conversion(){// This is the conversion i made to change the date to days over 1/1/1900

d--;

m--;

y = y - 1900;

daysOver =(y*365);// This creates the basic days in a year

daysOver = daysOver - (daysOver/4);//This adds an extra day every 4 years for the leap year day

daysOver = daysOver + d + (numDays*m) ;// This adds the days to the days in the years and then the months past in the year

System.out.println("The number of days after 1900 is"+" "+daysOver);// Prints out the days

}

publicvoid birthday(){// This is the conversion i made to change the date to days over 30/12/1987

d = d - 30;

m = m - 12;

y = y - 1987;

System.out.println("The number of days after 1987 is"+" "+daysOver);// Prints out the days

}

publicvoid reset(){

d = 1;// A section of code to reset the Date to 1/1/2007

m = 1;

y = 2007;

}

publicint getDay(){// Returns the day

return d;

}

publicint getMonth(){// Returns the month

return m;

}

publicint getYear(){// Returns the year

return y;

}

publicvoid output(){// Returns the values or day, month and year as a print out.

System.out.println("The date is "+d+"/"+m+"/"+y);

}

}

[8297 byte] By [IfAllElseFailsa] at [2007-11-26 20:00:05]
# 1
The date at the top was meant to be 1/1/1900.The commenting is wrong when assigning :d=27m=2y=2007It should have read "Fills the 3 ints 27/2/07 initially."
IfAllElseFailsa at 2007-7-9 22:57:21 > top of Java-index,Java Essentials,Java Programming...
# 2

This line doesn't match the comment, and doesn't make sense (the comment is more correct than the code).

daysOver = daysOver - (daysOver/4); //This adds an extra day every 4 years for the leap year day

As for birthday, it doesn't make sense to subtract 30 from 'd' and 12 from 'm'. That will make invalid month and day values.

doremifasollatidoa at 2007-7-9 22:57:21 > top of Java-index,Java Essentials,Java Programming...
# 3
oo yer, i should really fix that line.If its wrong to subtract those values could you please tell me the correct way to do it rather than just say its wrong because you aint really helping.
IfAllElseFailsa at 2007-7-9 22:57:21 > top of Java-index,Java Essentials,Java Programming...
# 4

The update code for the two bits is

public void conversion(){ // This is the conversion i made to change the date to days over 1/1/1900

d--;

m--;

y = y - 1900;

daysOver =(y*365); // This creates the basic days in a year

daysOver = daysOver + (y/4) ; //This adds an extra day every 4 years for the leap year day

daysOver = daysOver + d + (numDays*m) ; // This adds the days to the days in the years and then the months past in the year

System.out.println("The number of days after 1900 is"+" "+daysOver); // Prints out the days

}

public void birthday(){ // This is the conversion i made to change the date to days over 30/12/1987

d = d - 30;

m = m - 12;

y = y - 1987;

daysOver =(y*365); // This creates the basic days in a year

daysOver = daysOver + (y/4) ; //This adds an extra day every 4 years for the leap year day

daysOver = daysOver + d + (numDays*m) ; // This adds the days to the days in the years and then the months past in the year

System.out.println("The number of days after 1987 is"+" "+daysOver); // Prints out the days

}

IfAllElseFailsa at 2007-7-9 22:57:21 > top of Java-index,Java Essentials,Java Programming...
# 5
That code works but the result is out by 23 days to what it should be.Any ideas?
IfAllElseFailsa at 2007-7-9 22:57:21 > top of Java-index,Java Essentials,Java Programming...
# 6

> That code works but the result is out by 23 days to what it should be.Any ideas?

That doesn't sound like it works to me. If it "worked", it would give the correct answer.

You didn't show your test driver (the code where you "prove" that it "worked"). I have no idea what you are doing (your code is certainly odd).

You are still subtracting 30 from d and 12 from m. That still doesn't make sense.

doremifasollatidoa at 2007-7-9 22:57:21 > top of Java-index,Java Essentials,Java Programming...