/** * A class to represent a number of hours, minutes and seconds * * @author CSC 142 * */ public class Clock { // hours, minutes and seconds private int h, m, s; // no need to write this constructor. // If no constructor is written, Java automatically creates // a default constructor that initializes the instance fields // to their default values. public Clock() { h = 0; m = 0; s = 0; } /** * Adds one second to the current time of the clock */ public Clock tick() { s++; // same as s+=1 or s = s + 1 if (s == 60) { m++; s = 0; if (m == 60) { m = 0; h++; } } return this; } /** Returns the time of the clock as a string */ public String toString() { return "h=" + h + ", m=" + m + ", s=" + s; } }