Question: Write on java Suppose you have the class Date at right. Write an instance method isBefore to be placed inside the Date class. The method

 Write on java Suppose you have the class Date at right.

Write on java Suppose you have the class Date at right. Write an instance method isBefore to be placed inside the Date class. The method accepts another Date as a parameter and returns true if this date comes earlier in the year than the date passed in. If this date comes later in the year than the date passed, or if the two dates are the same, the method returns false. For example, if these Date objects are declared in client code: Date jan01 = new Date( 1, 1); Date jul04 = new Date( 7, 4); Date jul22 = new Date( 7, 22); Date sep19 = new Date( 9, 19); Date deco3 = new Date(12, 3); The following calls should return true: jul04.isBefore(jul22) sep19.isBefore(deco3) jan01.isBefore( sep19) The following calls should return false: deco3.isBefore(ju122) jul22. isBefore(jul04) sep19.isBefore( sep19) Your method should not modify the state of either Date object, such as by modifying their day or month fields. // this class ignores leap years public class Date { private int month; private int day; // constructs the given month/day public Date(int m, int d) // returns the day public int getDay() // returns the month public int get Month() // returns the number of days // in this date's month. public int daysInMonth() // compares dates (true if same) public boolean equals(Date d) // modifies this date's state // forward in time by 1 day, // wrapping month/year if needed public void nextDay() // set month/date to given values public void setDate(int m, int d) 1/ your method would go here }

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!