Create a class named DateClass. It should contain three fields for the month, day and year. Create a two constructors. The first initializes the fields to any value that you want, and the second should accept three arguments, one for each field, the constructor then initializes the fields to these arguments. The class should also have a getDateString method that returns the specified date in MMMM dd yyyy format (i.e.Wednesday September 28, 2005). Be sure that invalid dates are not accepted, (i.e. Feb 29 2005). Lastly, include a method named isLeapYear which returns true if the date is a leap year, false otherwise.
My problem is on how to get the day of the week. Example, Wednesday September 28, 2005... thanks alot.. God bless you...
publicclass DateClass{
// Or you can make these Strings
// Default constructor...
int month, day, year;
public DateClass(){
month = 1;
day = 1;
year = 2005;
}
public DateClass(int month, int day, int year){
this.month = month;
if((month == 2)&&(day > 29)){
// do whatever validation you need for day
// in this case default to last Feb day
// may test for leap year -- check out
// www.kmatech.co.uk for possible verification
// algorithm - or an idea - don't kill my bandwidth
// though, coz its not a corporate website.
// Though it does give the impression that it is.
// There is a section that says click HERE
// it has code of something similar in reverse thinking
// That would cater for leap years etc...
this.day = 29;
}else{
this.day = day;
}
this.year = year;
}
publicvoid setMonth(int month){
this.month = month;
}
publicint getMonth(){
return this.month;
}
// create Getters and setters for day and year...
// in effect this is what you call a Container Class
// You can set your attributes and retrieve values
// for the current object
}
Enjoy debugging whatever typos I've whipped in... Oops, the payment hour has started, gotta jet... Good luck...