package test3; /** * A class that represents time in one day using hours and minutes. The time is * based on a 24-hour clock: The start of each day is midnight or 0 hours and 0 * minutes, noon is 12 hours and 0 minutes, and the end of the day is 23 hours * and 59 minutes. * *
* The time represented by
* The result is the difference in minutes between
* The result is SimpleTime
does not automatically change
* with the passing of time; a client is able to manually set the time using the
* provided mutator methods.
*
* @author EECS1030_2014_15_W
*
*/
public class SimpleTime implements ComparableSimpleTime
object that represents the same time as
* another SimpleTime
object.
*
* @param other
* the SimpleTime
object to copy
*/
public SimpleTime(SimpleTime other) {
}
/**
* Create a SimpleTime
representing the time with the given hour
* and minute.
*
* @param hour
* the hour of the day
* @param minute
* the minute of the hour
* @throws IllegalArgumentException
* if hour
is not in the range 0-23
* @throws IllegalArgumentException
* if minute
is not in the range 0-59
*/
public SimpleTime(int hour, int minute) {
}
/**
* Get the hour of the day (0-23) represented by this object.
*
* @return the hour
*/
public int getHour() {
}
/**
* Set the hour of the day (0-23) represented by this object.
*
* @param hour
* the hour to set
* @throws IllegalArgumentException
* if hour
is not in the range 0-23
*/
public void setHour(int hour) {
}
/**
* Get the minute of the hour (0-59) represented by this object.
*
* @return the minute
*/
public int getMinute() {
}
/**
* Set the minute of the hour (0-59) represented by this object.
*
* @param minute
* the minute to set
* @throws IllegalArgumentException
* if minute
is not in the range 0-59
*/
public void setMinute(int minute) {
}
/**
* Compares this SimpleTime
object to another
* SimpleTime
object.
*
* 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
.
*
* @return the difference in minutes between this
time and the
* other
time.
*/
@Override
public int compareTo(SimpleTime other) {
}
/**
* Returns the SimpleTime
object equal to noon (12:00)
*
* @return the SimpleTime
object equal to noon (12:00)
*/
public static SimpleTime noon() {
}
/**
* Generate a hash code for this object.
*
* @return a hash code for this object
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + this.hour;
return result;
}
/**
* Compare this SimpleTime
to an object for equality.
*
* 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).
*
* @return true
if both SimpleTime
objects represent
* the same time of day.
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (this.getClass() != obj.getClass()) {
return false;
}
SimpleTime other = (SimpleTime) obj;
if (this.hour != other.hour) {
return false;
}
if (this.minute != other.minute) {
return false;
}
return true;
}
/**
* Returns a string representation of the time of day. The string has the
* format 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.
*
* @return the time of day represented by this object as a string
*/
public String toString() {
return String.format("%2d:%02d", this.getHour(), this.getMinute());
}
}