Question: Exercises 4 . 4 Create a class named Time 2 which contains three variables: hour ( an int between 1 and 2 4 inclusive )

Exercises 4.4
Create a class named Time2 which contains three variables: hour (an int between 1 and 24 inclusive), minute (an int between 0 and 59 inclusive), and second (an int between 0 and 59 inclusive).
Include five overloaded constructors listed below:
1. The first constructor initializes the Time2 object to 01:01:01.
2. The second constructor initializes the Time2 object with a given hour, minute, and second.
3. The third constructor initializes the Time2 object with a given hour (e.g.,03:00:00).
4. The fourth constructor initializes the Time2 object with a given hour and minute (e.g.,03:25:00).
5. The fifth constructor initializes the Time2 object with another Time2 object.
In addition to the mutators and accessors, the class also includes the following methods:
1. militaryTime(), which returns the time in the format of 14:23:12.
2. standardTime(), which returns the time in the format of 02:23:12 PM.
Add a Time2Test class with the main() method called Time2Test. In the main() method, create five objects of Time2 class, each matching a constructor of the Time2 class. Then, display all five objects in both military and standard time formats.

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 Programming Questions!