public class Date {
private int day;
private String month;
private int year;
/**
* Creates a instance of a date and starts it on November 2, 2010
*/
public Date() {
day = 2;
month = "November";
year = 2010;
}
/**
* Creates a date where the user specifies the date to start on.
* The month must contain a string with a valid month name.
* The day must contain an integer with values between 1-30 or 1-31 depending on the date.
* Note that February and leap year are exceptions.
* The year must be non negative.
*/
public Date (String month, int day, int year) {
if (month=="January"||month=="February"||month=="March"||month=="April"||month=="May"||month=="June"||month=="July"||month=="August"||month=="September"||month=="October"
||month=="November"||month=="December") {
this.month = month;
}
else { //how to handle a bad input?
}
this.day = day;
if (year > 0) {
this.year = year;
}
else { //how to handle a bad input?
}
}
/**
* @ensure that the month, day, and year are all valid inputs.
* @return Date returns the current date in the form of a string
*/
public String getDate() {
return month + " " + day + "," + " " + year + ".";
}
/**
* @return day the day of the current date.
*/
public int getDay() {
return day;
}
/**
* @return month the month of the current date. The month must be capitalized and spelled correctly.
*/
public String getMonth() {
return month;
}
/**
* @return year returns the year of the current date. The year must be a non-negative number.
*/
public int getYear() {
return year;
}
public void nextWeek() {
day = day + 7;
}
public void tomorrow() {
}
}