Question: Lab Exercise 04.1 The Clock class USE JAVA This exercise will ask you to design a Clock class which will display the time in digital

Lab Exercise 04.1

The Clock class

USE JAVA

This exercise will ask you to design a Clock class which will display the time in digital format (ex: 10:45:13 pm). You will design and implement the class to do calculations in clock time. The Clock will contain, at a minimum, the following attributes:

The current time hours (0..12) - integer

The current time minutes (0..59 - integer

The current time seconds (0..59) integer

The day-cycle of the current time (a.m. or p.m.)

A printable version of the current time Ex: 10:02:41 a.m. string

The Clock will contain, at a minimum, the following methods:

A constructor that accepts 3 arguments, hours, minutes and seconds and sets the day-cycle to a.m.

A constructor that accepts 3 arguments, hours, minutes and seconds and sets the day-cycle to p.m.

A constructor that accepts no arguments and sets the current time to midnight.

A method that accepts as an argument, the name of another object of class-clock and returns the hours, minutes and seconds between the current time and the time in the argument object.

A method that accepts 3 arguments, hours, minutes, seconds and uses these values to set the current time.

Testing: You will test this class by creating several Clock objects and exercising the various methods. All input must be validated.

The program must prompt the user to enter times for Clock A and Clock B. For Example: Enter hours for clock A then enter minutes and then seconds and then either a.m. or p.m. The program cannot allow the user to enter an invalid amount of hours, minutes and seconds. The limits are nothing over 12 for hours, nothing over 59 for minutes and nothing over 59 for seconds. If the user enters anything above those limits then prompt them to enter a correct amount of time. For example: If they enter 79 seconds then prompt the user with "Invalid amount of seconds, Enter Seconds again" keep prompting them with this statement until they answer with a correct amount. Then once they answer correctly move on to the next question. When getting the time difference from the two clocks the resulting amount of hours, minutes and seconds must all be positive.

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!