Class Time

java.lang.Object
  extended by Time

public class Time
extends java.lang.Object

This class represents time using hours and minutes (seconds are not represented). Feel free to add any methods that you want.

Author:
Dept of Computer Science, UMCP

Constructor Summary
Time(int hour, int minutes, java.lang.String amPm)
          Initializes the object using specified parameter values.
 
Method Summary
 int compareTo(Time time)
          Compares two time objects.
 boolean equals(java.lang.Object obj)
          Compares two time objects.
static Time increaseByMinutes(Time time, int minutes)
          Returns a new time object corresponding to the time we will have after increasing the time parameter by the specified number of minutes.
 java.lang.String toString()
          Returns a string using the format "hour:minutes am" or "hour:minutes pm".
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Time

public Time(int hour,
            int minutes,
            java.lang.String amPm)
Initializes the object using specified parameter values.

Parameters:
hour - value between 1 and 12, both inclusive
minutes - value between 0 and 59, both inclusive
amPm - either "am" or "pm"
Throws:
java.lang.IllegalArgumentException - Thrown for invalid hour, minutes, or amPm value. Validity for hour is verified first, followed by the minutes' validity and the am/pm value's validity. The thrown exception must use one of the following messages: "Invalid hour value", "Invalid minutes value", or "Invalid am/pm value".
Method Detail

toString

public java.lang.String toString()
Returns a string using the format "hour:minutes am" or "hour:minutes pm". A single space is used in between minutes and am/pm. The minutes always appear with two digits (e.g., 0 minutes will be "00").

Overrides:
toString in class java.lang.Object
Returns:
string representation for the Time object

equals

public boolean equals(java.lang.Object obj)
Compares two time objects. Two time objects are considered equal if they represent the same time.

Overrides:
equals in class java.lang.Object
Returns:
true if the objects are considered equal and false otherwise

compareTo

public int compareTo(Time time)
Compares two time objects. Returns -1 if the current object is a time that precedes the time parameter, 0 if the current object and the time parameter represent the same time, and 1 if the current object represents a time that is after the time parameter.

Returns:
-1, 0, or 1

increaseByMinutes

public static Time increaseByMinutes(Time time,
                                     int minutes)
Returns a new time object corresponding to the time we will have after increasing the time parameter by the specified number of minutes. Notice that the number of minutes could exceed the number of minutes in a day, in which case the resulting time for the next day should be returned.

Keep in mind that the time parameter is not modified by this method.

Parameters:
time -
minutes - delta to apply to time parameter
Returns:
time object with delta applied