Java program will not work
807599Apr 19 2007 — edited Apr 19 2007our tutor has given us the following code. Now we have to extend this code with a few more methods. The problem is that the code she has given us will not compile so i have to find out what is wrong with it before i can start doing my work. I am not good in java but when i try to compile it i get a
'class' or 'interface' expected (this error is for line 1). Any help would be appriciated because i need to starty with this ASAP
pulic class Date extends Object {
private int month;
private int day;
private int year;
public Date (int theMoth, int theDay, int theYear)
{
if (theMonth >0 && the Month <= 12)
month = theMonth;
else {
month = 1;
System.out.println ("Month " + theMonth +
" invalid. Set to month 1." );
}
year = theYear;
day = checkDay (theDay);
System.out.println(
"Date object constructor for date " + toString());
} public int checkDay (int testDay)
{ int dayPerMonth [] =
{0,31,28,31,30,31,30,31,31,30,...
if ( testDay >0 && testDay <= daysPerMonth[month] )
return testDay;
if ( month ==2 && testDay == 29 && (year % 400 == 0 ||
(year % 4 == 0 && year % 100 != 0 )))
return testDay;
System.out.println ( "Day " + testDay + " invalid. Set to day 1." );
return 1; }
public String toString() {
return month + "/" + day + "/" + year;
}
}