Does anyone know how to write a controller class? I've been asked to write one for my date class to make sure that it works ok:
public class Date
// private variables
{
private int day;
private int month;
private int year;
// constructors
public Date ()
{
day = 0;
month = 0;
year = 0;
}
public Date (int dd,int mm,int yyyy)
{
day = dd;
month = mm;
year = yyyy;
}
public Date (Date other)
{
day = other.day;
month = other.month;
year = other.year;
}
// accessors
public int getDay()
{
return day;
}
public int getMonth()
{
return month;
}
public int getYear()
{
return year;
}
public String monthAsString()
{
switch (month)
{
case 1 : return "January";
case 2 : return "February";
case 3 : return "March";
case 4 : return "April";
case 5 : return "May";
case 6 : return "June";
case 7 : return "July";
case 8 : return "August";
case 9 : return "September";
case 10 : return "October";
case 11 : return "November";
case 12: return "December";
default : return "error - this month does not exist";
}
}
public boolean equals(Date other)
{
if (year == other.year && month == other.month && day == other.day)
return true;
else return false;
}
public boolean earlierThan(Date other)
{
if (year < other.year)
return true;
else if (year == other.year)
{
if (month < other.month)
return true;
else if (month == other.month)
{
if (day < other.day)
return true;
else return false;
}
else return false;
}
else return false;
}
public String toString()
{
return day + " " + monthAsString() + " " + year;
}
public void copy (Date other)
{
day = other.day;
month = other.month;
year = other.year;
}
}