import java.text.DecimalFormat; /** * TimeDuration is an interval of time. * The interval is in minutes and seconds (whole numbers). * Intervals greater than 60 minutes do not "roll over" to hours. * * @author J. Dalbey * @version 9/2009 */ public class TimeDuration { /* duration is represented in seconds */ private Natural duration; /** * Construct a time duration with a given initial number of seconds. * @param initialSeconds integer value of seconds
* @pre 0 <= initialSeconds
*/ public TimeDuration(int initialSeconds) /** * Construct a time duration with a given initial value for minutes * and seconds. * @param initialMinutes integer value of minutes * @param initialSeconds integer value of seconds
* @pre 0 <= initialMinutes <= 999
* @pre 0 <= initialSeconds <= 59
*/ public TimeDuration(int initialMinutes, int initialSeconds) /** * Accessor to number of minutes. * @return the minutes component of this TimeDuration */ public int minutes() /** Return duration as seconds. * @return int duration as number of seconds. */ public int seconds() /* Convert a Natural to a TimeDuration */ private static TimeDuration toTimeDuration(Natural nat) /** * Returns a TimeDuration whose value is (this + val). * * @param val value to be added to this TimeDuration. * @return this + val */ public TimeDuration add(TimeDuration val) /** * Returns a TimeDuration whose value is (this - val). * * @param val value to be subtracted from this TimeDuration. * @return this - val * @throws ArithmeticException if result would be negative. */ public TimeDuration subtract(TimeDuration val) /** * Compares this TimeDuration with the specified Object for equality. * * @param x Object to which this TimeDuration is to be compared. * @return true if and only if the specified Object is a * TimeDuration whose value is numerically equal to this TimeDuration. */ public boolean equals(Object x) /** * Return a displayable representation of this time interval. * @return the time in a common "MM:SS" format */ public String toString() }