Assignment 2: Writing Classes - Due June 23
The Date Class
Write your own implementation of a Date class. Your class should provide the following
- Two constructors, one that takes no arguments, and one that takes three integers,
month, day, and year. (figure out good values to set for the default (zero argument) constructor)
- Provide 1 mutator - a setDate methods that takes three integers (month, day and year), and has no return value
- Provide 3 accessors - getDay, getMonth and getYear.
- Provide an equals method (checks if the dates are the same)
- Provide an compareTo method (returns -1 if this object is being compared to a past date, returns 0 if they are the same, and returns 1 if it is being compared to a future date) - your class now implements the Comparable interface - so go ahead and declare that up in the Class definition.
- Provide a toString method that returns a string representing the object
- Provide an isValidDate method, which checks to see if the date is valid.
This method should be static (you don't need an instance of the
class to use it.). It should take 3 integers, and return a boolean representing whether
the date is valid. (Ignore the leap year factor, assume February always has 28 days)
- Define an Exception called IllegalDateException, and throw it whenever an invalidate
date is attempted to be set.
- Extra Credit 5% - Implement the Cloneable interface and make your
class Cloneable by writing a clone() method.
- Extra Credit 5% - Make isValidDate() check for leap years - show this in your testing program.
Be sure to write javadoc comments for your class, and to comment code well.
Write a testbed program that creates several Date classes, tests all the methods,
and attempts to set illegal values.
Turn in all your code, your testbed program + run, and your javadoc