public class Date
{
private int month;
private int day;
private int year;
public Date (int month, int day, int year)
{
int newMonth = month;
int newDay = day;
int newYear = year;
}
public boolean isValid()
{
if (year >= 1582)
if(month >= 1 && month <=12)
if (month == 4 || month == 6 || month == 9 || month== 11)
if (day >=1 && day <= 30)
return true;
else
return false;
else
if (month == 2)
if (isLeapYear())
if (day >=1 && day <= 29)
return true;
else
return false;
else
if (day >= 1 && day <=28)
return true;
else
return false;
else
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
if (day >=1 && day <= 31)
return true;
else
return false;
else
return false;
else
return false;
else
return false;
}
public String toString()
{
switch (month)
{
case 1:
return "January" + "," + day + "," + year;
case 2:
return "February" + "," + day + "," + year;
case 3:
return "March" + "," + day + "," + year;
case 4:
return "April" + "," + day + "," + year;
case 5:
return "May" + "," + day + "," + year;
case 6:
return "June" + "," + day + "," + year;
case 7:
return "July" + "," + day + "," + year;
case 8:
return "August" + "," + day + "," + year;
case 9:
return "September" + "," + day + "," + year;
case 10:
return "October" + "," + day + "," + year;
case 11:
return "November" + "," + day + "," + year;
case 12:
return "December" + "," + day + "," + year;
default:
return "No such month";
}
}
private boolean isLeapYear()
{
if (year % 4 == 0)
if (year % 100 == 0 && year % 400 !=0)
return true;
else
return false;
else
return false;
}
}