Question: The Date class. The Date class will represent a date. (Java has both Date and Calendar in the API, but both are more complex than

The Date class. The Date class will represent a date. (Java has both Date and Calendar in the API, but both are more complex than needed for this homework.) Our Date class will consist of three int values that represent the day, month, and year. The values for a Date instance will not change once they are set by the constructor. The Date class should have the following methods:

getDay Takes no input and returns an int. Returns the day of the date. The day should be a value between 1 and 31.

getMonth Takes no input and returns an int. Returns the month of the date. The month should be between 1 and 12.

getYear Takes no input and returns an int. Returns the year of the date.

toString you are to override the toString method inherited from Object so that the value returned is in the form "month/day/year".

equals you are to override the equals method inherited from Object so that this date is equal to the input object if that object is a Date with the same day, month and year as this date.

daysFromJan1 Takes no input and returns an int. Returns the number of days between this Date and January 1 of the same year. Do not write a loop to compute this. Instead use a large if statement based on the month of the Date. You may assume there are no leap years.

difference A class method that takes two Dates as input and returns a int. The value returned is the difference in days between them. If the first Date input comes after the second Date, the difference should be positive. If the first Date input comes before the second Date, the difference should be negative. You may ignore leap years in computing the difference. Do not use a loop to do this. Instead figure out a formula that you can use to calculate the difference.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!