monthlyCalendar
Class Time

java.lang.Object
  extended by monthlyCalendar.Time
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<Time>

public class Time
extends java.lang.Object
implements java.lang.Comparable<Time>, java.lang.Cloneable

This class represents time using hours and minutes (seconds are not represented). The internal representation of the class is up to you. One possible representation is to represent time as the number of minutes from midnight.

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
 java.lang.Object clone()
          Returns a duplicate (deep copy) of the object.
 int compareTo(Time time)
          Compares two time objects.
 boolean equals(java.lang.Object obj)
          Compares two time objects.
 int hashCode()
          Returns a hash code for the object based on the string representation for the object.
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, 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

hashCode

public int hashCode()
Returns a hash code for the object based on the string representation for the object.

Overrides:
hashCode in class java.lang.Object
Returns:
hash code value

clone

public java.lang.Object clone()
Returns a duplicate (deep copy) of the object.

Overrides:
clone in class java.lang.Object
Returns:
duplicate

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.

Specified by:
compareTo in interface java.lang.Comparable<Time>
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


Web Accessibility