public class SimpleTime extends Object implements Comparable<SimpleTime>
The time represented by SimpleTime does not automatically change
with the passing of time; a client is able to manually set the time using the
provided mutator methods.
| Modifier and Type | Field and Description |
|---|---|
static int |
MINUTES_PER_HOUR
The number of minutes in an hour
|
static int |
NOON_HOUR
The hour for noon.
|
| Constructor and Description |
|---|
SimpleTime(int hour,
int minute)
Create a
SimpleTime representing the time with the given hour
and minute. |
SimpleTime(SimpleTime other)
Create a
SimpleTime object that represents the same time as
another SimpleTime object. |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(SimpleTime other)
Compares this
SimpleTime object to another
SimpleTime object. |
boolean |
equals(Object obj)
Compare this
SimpleTime to an object for equality. |
int |
getHour()
Get the hour of the day (0-23) represented by this object.
|
int |
getMinute()
Get the minute of the hour (0-59) represented by this object.
|
int |
hashCode()
Generate a hash code for this object.
|
static SimpleTime |
noon()
Returns the
SimpleTime object equal to noon (12:00) |
void |
setHour(int hour)
Set the hour of the day (0-23) represented by this object.
|
void |
setMinute(int minute)
Set the minute of the hour (0-59) represented by this object.
|
String |
toString()
Returns a string representation of the time of day.
|
public static final int NOON_HOUR
public static final int MINUTES_PER_HOUR
public SimpleTime(SimpleTime other)
SimpleTime object that represents the same time as
another SimpleTime object.other - the SimpleTime object to copypublic SimpleTime(int hour,
int minute)
SimpleTime representing the time with the given hour
and minute.IllegalArgumentException - if hour is not in the range 0-23IllegalArgumentException - if minute is not in the range 0-59hour - the hour of the dayminute - the minute of the hourpublic int getHour()
public void setHour(int hour)
IllegalArgumentException - if hour is not in the range 0-23hour - the hour to setpublic int getMinute()
public void setMinute(int minute)
IllegalArgumentException - if minute is not in the range 0-59minute - the minute to setpublic int compareTo(SimpleTime other)
SimpleTime object to another
SimpleTime object.
The result is the difference in minutes between this time and
the other time. For example, if the time represented by
this time is 11:00 and the time represented by
other time is 13:05 then this.compareTo(other) returns
-125.
compareTo in interface Comparable<SimpleTime>this time and the
other time.public static SimpleTime noon()
SimpleTime object equal to noon (12:00)SimpleTime object equal to noon (12:00)public int hashCode()
public boolean equals(Object obj)
SimpleTime to an object for equality.
The result is true if and only if obj is a
SimpleTime object, and both objects represent the same time of
day (i.e., identical hours and identical minutes).
public String toString()
XX:YY where XX is the hour of the day and
YY is the minute of the day. Both the hour and minute fields
are always two characters wide.