Create a class that encapsulates integers used to represent


Question: Time Class

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 0 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.

2379_Figure.jpg

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Create a class that encapsulates integers used to represent
Reference No:- TGS02374333

Now Priced at $10 (50% Discount)

Recommended (91%)

Rated (4.3/5)