logo Practice-It logo

rewind

Language/Type: Java classes instance methods
Related Links:
Author: Marty Stepp (on 2011/12/14)

Write an instance method rewind to be placed inside the Date class. The method accepts an integer representing a number of days as a parameter and modifies the Date's state by moving it backward in time by that many days. You may assume that the value passed is non-negative, but it could be very large, causing the Date to wrap into previous month(s) or year(s).

For example, if these Date objects are declared in client code:

Date jan10 = new Date(1, 10);
Date sep19 = new Date(9, 19);
Date nov30 = new Date(11, 30);

The following calls should change their state as indicated:

sep19.rewind(0);         // 9/19
sep19.rewind(5);         // 9/14
sep19.rewind(15);        // 8/30
jan10.rewind(11);        // 12/30 (of last year)
nov30.rewind(365 + 364); // 12/1 (two years ago)
Type your solution here:


This is a partial class problem. Submit code that will become part of an existing Java class as described. You do not need to write the complete class, just the portion described in the problem.

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.