Question: Develop a pair of classes that work together to represents a date, a Date class and a Month class. The Date class should have integer

Develop a pair of classes that work together to represents a date, a Date class and a Month class. The Date class should have integer attributes for the day of the month and year and a reference to a secondary Month object. The Month class should have an integer attribute for the month number and a reference back to the Date class that owns it.
The Month class should possess the following features:
A two-argument constructor that receives the month number and a reference to a Date object. (There should NOT be a default constructor.)
Public accessor and mutator for the month number attribute.
Public increment and decrement methods to update the month number by 1. Remember that the month number must always stay between 1 and 12, so these methods must handle the beginning and ending of the year properly..
Public getMonthName method that returns a String representing the name of the month (January,February, etc.).
Public getDaysInMonth method that returns the number of days in the month. Be sure to take leap years into account here.
If a month number is received that is outside the range 1 to 12, throw a DateTimeException. The DateTimeException is defined in the Java Library.
The Date class should possess the following features:
A three-argument constructor that receives the month number, the day number, and a year number (all of them are ints).
Public accessors and mutators for all three attributes. The accessor and mutator for the month attribute should receive and return an int, not a Month object. Any time any of the attributes change, the new values should be checked to ensure that they represent a valid date. Invalid dates should cause a DateTimeException to be thrown. Hint: You may want to include another method specifically for the purpose of validating the dates.
Public isLeapYear method that checks if the year number constitutes a leap year.
Public addDays and SubtractDays methods that update the stored date by the number of days given as the parameter. Note that adding or subtracting days will eventually cause the month attribute to change. Likewise, enough days will cause the year attribute to change as well. Adding one day the December 31,2019 should produce January 1,2020.
Public toString method that return a String representation of the date in the following form: March 2,2020.
Implement the Comparable interface and override the compareTo method.
Override the equals method.
Make proper use of the @Override annotation and the instanceof operator.

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 Programming Questions!