Exercise 3 (Compulsory)
Write a Java class Clock for dealing with the day time represented by hours,
minutes, and seconds. Your class must have the following features:
● Three public instance variables for the hours (range 0 - 23),
minutes (range 0 - 59), and seconds (range 0 - 59).
● Three constructors:
○ default (with no parameters passed; should initialize the
represented time to 12:00:00)
○ a constructor with three parameters: hours, minutes,
and seconds.
○ a constructor with one parameter: the value of time in
seconds since midnight (it should be converted into the
time value in hours, minutes, and seconds)
● Instance methods:
○ Public void Clockinfo(): with no parameters to your
class. Clockinfo() must return a String representation of
the Clock object in the form "(hh:mm:ss)", for example
"(03:02:34)".
○ Public Boolean isEqual(): which compares two
instances of the class Clock, and returns true if they
have the same information, and false if they do not.
Write a separate class ClockDemo with a main() method to performs the
following tasks:
● Create a Clock object firstClock using one integer seconds since
midnight obtained from the keyboard.
● Create a Clock object secondClock by using three integers
(hours, minutes, seconds) read from the keyboard.
● Use the isEqual() method to compare between the two objects.
Sample Output:
Eneter the time in seconds
45015
Enter three integers representing the time in hours, minutes, and seconds
Hours:12
Minutes:30
Seconds:15
(12:30:15)
(12:30:15)
Is firstClock equal to SecnodClock? true