Important Notice:

Practice-It will be discontinued as of November 1st, 2024. After this date, the website will remain online for a transitional period, but login will be restricted to University of Washington NetID authentication. This marks the next phase towards the platform's full retirement. Thank you for your use and support of the application over the years.

If you are looking for an alternative, a similar tool, CodeStepByStep, was developed independently by the original author of Practice-It, and is available at codestepbystep.com**

logo Practice-It logo

BJP3 Exercise 5.17: monthApart

Language/Type: Java method basics return
Author: Whitaker Brand (on 2013/04/01)

Write a method named monthApart that accepts four integer parameters representing two calendar dates. Each date consists of a month (1 through 12) and a day (1 through the number of days in that month [28-31]). The method returns whether the dates are at least a month apart. Assume that all dates in this problem occur during the same year. For example, the following dates are all considered to be at least a month apart from 9/19 (September 19): 2/14, 7/25, 8/2, 8/19, 10/19, 10/20, and 11/5. The following dates are NOT at least a month apart from 9/19: 9/20, 9/28, 10/1, 10/15, and 10/18. Note that the first date could come before or after (or be the same as) the second date. Assume that all parameter values passed are valid.

Sample calls:

Call Returns Because
monthApart( 6, 14, 9, 21) true June 14th is at least a month before September 21st
monthApart( 4, 5, 5, 15) true April 5th is at least a month before May 15th
monthApart( 4, 15, 5, 15) true April 15th is at least a month before May 15th
monthApart( 4, 16, 5, 15) false April 16th is NOT at least a month before May 15th
monthApart( 6, 14, 6, 8) false June 14th is NOT at least a month apart from June 8th
monthApart( 7, 7, 6, 8) false July 7th is NOT at least a month apart from June 8th
monthApart( 7, 8, 6, 8) true July 8th is at least a month after June 8th
monthApart( 10, 14, 7, 15) true October 14th is at least a month after July 15th
Type your solution here:


This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.