Time.java Source code

Java tutorial

Introduction

Here is the source code for Time.java

Source

public class Time implements Comparable {
    private int hour, minute;

    public Time(int hh, int mm) {
        this.hour = hh;
        this.minute = mm;
    }

    public int compareTo(Object o) {
        Time t = (Time) o;
        return hour != t.hour ? hour - t.hour : minute - t.minute;
    }

    public boolean equals(Object o) {
        Time t = (Time) o;
        return hour == t.hour && minute == t.minute;
    }

    public int hashCode() {
        return 60 * hour + minute;
    }
}