Question
In this lab you will write a class called Time. The Time class will have three data members: hours, minutes, and seconds (all ints). Times
In this lab you will write a class called Time. The Time class will have three data members: hours, minutes, and seconds (all ints). Times will be stored using a 24 hour clock, so 10 AM is stored as 10 and 10 PM is stored as 22.
Your Time class should have the following member functions:
default constructor
This function initializes the Time object to contain 12 midnight (hour zero, minutezero, seconds zero).
constructor with three parms
This function has parms for the hour, minutes, and secconds. It initializes the Time object to the values given by the parms.
copy constructor
This function initializes the Time object to contain the same values as the parm.
setTime
This function has parms for the hour, minute, and second, and returns void.setTime sets the time to the values given by the parms.
showTime
This function has no parms and returns void. It prints the time using the normal 12 hour clock and AM/PM designation. For example, if hours is 21, minutes is 32 and seconds is 5, the time should be displayed as 9:32:05 PM. If hours is 5, minutes is 12, and seconds is 45, the time should be displayed as 5:12:45 AM. Don't forget to add a leading zero if the minutes and/or the seconds contains a value less than 10!
tick
This function has no parms and returns void. It increments the time by onesecond, adjusting the minutes and hours if necessary.
less
This function returns an int and has a Time object as its parm. It returns 0 (false) if the time in the invoking object is before the time in the parm, and it returns 1 (true) if the time in the invoking object is not before the time in the parm.
Write client code to test your Time class. Your main function should:
- Create two Time objects and prompt the user to enter values for the Time objects.
- Print the Time objects.
- Print a message that tells which Time object contains a shorter distance.
- Tick the first Time object 10 times, then print the first Time object.
- Create a third Time object that is initialized by the default constructor.
- Create a fourth Time object that is initialized to 10:56:05AM.
- Create a fifth Time object that is initialized to be a copy of the fourth Time object.
- Print the third, fourth, and fifth Time objects.
Step by Step Solution
3.52 Rating (159 Votes )
There are 3 Steps involved in it
Step: 1
import javaio import javautil class Time int hoursminutesseconds Time hours 0 minutes0 seconds0 Timeint hint mint s thishoursh thisminutesm thissecond...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