Question: Write the program in JAVA Design a class named Timer that contains the following three private instance data fields: hours: an integer that holds the

Write the program in JAVA
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:
1. A no-arg constructor that creates a default Timer object (The data fields hours, minutes, seconds are defaulted to 0).
2. A constructor that constructs a Timer object with three specified values for hours, minutes, and seconds.
3. Three public setter methods for the data fields hours, minutes and seconds.
4. 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 0. e.g., if the value used to set the data field hours is negative, you should then set hours to 0 instead.
Write a test program to do the following tasks:
1. 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.
2. Calculate and print the total number of hours, minutes, and seconds in these three objects.
A sample dialog is:
Enter the first Timer object: 123
Enter the second Timer object: 456
Enter the third Timer object: 78-1[The object created should have 7,8, and 0 for the data fields hours, minutes, and seconds since -1 is invalid]
The total number of hours is 12(sum of 1,4 and 7)
The total number of minutes is 15(sum of 2,5, and 8)
The total number of seconds is 9(sum of 3,6 and 0)

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!