public class Date {
private int month, day, year; // holds month, day, year for date
/**
* Creates a Date object with the given month, day, and year.
* Invalid arguments are replaced with 0.
*
* @param m the month (1 <= m <= 12)
* @param d the day (1 <= d <= 31)
* @param y the year (1000 <= y <= 9999)
**/
public Date(int m, int d, int y) {
month = m;
if (month < 1 || month > 12)
month = 0;
day = d;
if (day < 1 || day > 31)
day = 0;
year = y;
if (year < 1000 || year > 9999)
year = 0;
}
/**
* Returns the month.
* @return the month
**/
public int getMonth() {
return month;
}
/**
* Returns the day.
* @return the day
**/
public int getDay() {
return day;
}
/**
* Returns the year.
* @return the year
**/
public int getYear() {
return year;
}
/**
* Returns a String representing the date.
* @return the date in the format: mm/dd/yyyy
public String toString() {
return (month + "/" + day + "/" + year);
}
}