Question
Lab Exercise 04.1 The Clock class PLEASE USE JAVA This exercise will ask you to design a Clock class which will display the time in
Lab Exercise 04.1
The Clock class
PLEASE 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 user should be allowed to enter times for Clock A and Clock B when the program is run. Example: Enter time for Clock A. Then the user inputs the time and is then prompted to enter a time for Clock B. If the user enters a invalid time prompt them to enter a correct time. Then the time difference is printed out.
Enter the inputed time in A.M. and P.M.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started