Another
Example
Develop and implement a
class Date that represents a date. A Date object should have 3
attributes: day of the month, the month, the year. The class should
provide the following constructors:
- a no argument constructor that configures a new date that
represents January 1, 2000.
- a constructor that configures a new date with the day, month
and year as parameters.
The class should provide the following behaviors:
- int getDay(): returns the day of the associated date.
- int getMonth()
- int getYear()
- void setDay(int d)
- void setMonth(int m)
- void setYear(int y)
- int compare(Date d): returns -1 if this Date object occurs
before d, 0 if this Date is the same as d, and 1 if d comes before this
Date object.
- String toString(): returns a text representation of the Date
object. Over-ride the method inherited from the Object class.
- boolean equals(): over-ride the method inherited from the Object class.
Also write a DateTest class that creates several Date objects
using information which is read from the user, and prints a String
representation of each date.