Question: Using the UML below, create a class that encapsulates integers used to represent hours, minutes and seconds for the time of day in 24 hour

 Using the UML below, create a class that encapsulates integers used

Using the UML below, create a class that encapsulates integers used to represent hours, minutes and seconds for the time of day in 24 hour format . It has four constructors, each passing in different ways a Time object can be created (use a value of O for variables not set during construction) The class also has getters and setters for each of these fields. The Time class should ensure that variables cannot be set below zero or some other invalid value eg: minutes and seconds should only be between 0-59, hours 0-23 Create a suitable toString method that prints the time as double digit format. Eg 10:30 pm should return "22:30:00" whereas 12:05 am should return the format "00:05:00". Override the equals method of Object so that two Time objects are considered equal if both have hours, minutes and seconds the same The class should also implement the Comparable interface comparing other times so that the earlier time takes precedence. Eg, if this current Time object is earlier in the day than the parameter object then a negative number should be returned. Time hours: int Comparable

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!