Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ITS ON JAVA Suppose you have the class Date at right. Write an instance method isBefore to be placed inside the Date class. The method

ITS ON JAVA

image text in transcribed

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. // 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(). 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(jul22) 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. // returns the month public int getMonth() // 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) // your method would go here }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions