Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Design a class named Timer that contains the following three private instance data fields: hours: an integer that holds the number of hours. minutes: an
Design a class named Timer that contains the following three private instance data fields: hours: an integer that holds the number of hours. minutes: an integer that holds the number of minutes. seconds: an integer that holds the number of seconds.
In addition, the class should have the following constructors and methods:
A noarg constructor that creates a default Timer object The data fields hours, minutes, seconds are defaulted to
A constructor that constructs a Timer object with three specified values for hours, minutes, and seconds.
Three public setter methods for the data fields hours, minutes and seconds.
Three public getter methods for the data fields hours, minutes and seconds.
In the second constructor and three setter methods above, make sure that the three data fields are greater than or equal to eg if the value used to set the data field hours is negative, you should then set hours to instead.
Write a test program to do the following tasks:
Prompt the user to enter three groups of values of hours, minutes and seconds and use these values to create an array of three Timer objects.
Calculate and print the total number of hours, minutes, and seconds in these three objects.
A sample dialog is:
The object created should
Enter the first Timer object: have and for the data
Enter the second Timer object: fields hours, minutes, and
Enter the third Timer object: seconds since is invalid.
The total number of hours is
The total number of minutes is
sum of and
The total number of seconds is
sum of and
sum of and
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