public class Time {
    private int hour; // 0 - 23
    private int min; // 0 - 59
    private int sec; // 0 - 59

    //use "this" in making constructors
    public Time(int hour, int min, int sec) {
        this.hour = hour;
        this.min = min;
        this.sec = sec;
    }

    public Time(int hour, int min) {
        // sec = 0
        this(hour, min, 0);
    }

    public Time(int hour) {
        // min = sec = 0
        this(hour, 0, 0);

    }

    public Time() {
        // hour = min = sec = 0
        this(0, 0, 0);
    }

    //setter, add parameters by yourself
    public void setTime(int hour, int min, int sec) {
        this.hour = hour;
        this.min = min;
        this.sec = sec;

    }

    //getters
    public int getHour() {
        return hour;
    }

    public int getMin() {
        return min;
    }

    public int getSec() {
        return sec;
    }

    //print time as HH:MM:SS
    public void printTime() {
        System.out.print(hour + ":" + min + ":" + sec);
    }

    public boolean isEarlyThan(Time anotherTime) {
        // compare by hour
        if (this.hour < anotherTime.hour) {
            return true;
        }
        else if (this.hour > anotherTime.hour) {
            return false;
        }
        else {
            // compare by min
            if (this.min < anotherTime.min) {
                return true;
            }
            else if (this.min > anotherTime.min) {
                return false;
            }
            else {
                // compare by sec
                if (this.sec < anotherTime.sec) {
                    return true;
                }
                else if (this.sec > anotherTime.sec) {
                    return false;
                }
                else {
                    return false;
                }
            }

        }
    }

    //compute difference between finishTime and beginTime
    public static Time duration(Time beginTime, Time finishTime){
        //convert to seconds
        int beginTimeInSec = beginTime.hour * 3600 + beginTime.min * 60 + beginTime.sec;
        int finishTimeInSec = finishTime.hour * 3600 + finishTime.min * 60 + finishTime.sec;
        int durationInSec = finishTimeInSec - beginTimeInSec;

        Time duration = new Time();

        //convert duration to Time
        duration.hour = durationInSec / 3600; // get the quotient
        durationInSec %= 3600; // get the remainder

        duration.min = durationInSec / 60; // get the quotient
        durationInSec %= 60; // get the remainder

        duration.sec = durationInSec;

        return duration;

    }

}
