Answered step by step
Verified Expert Solution
Link Copied!

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 no-arg constructor that creates a default Timer object (The data fields hours, minutes, seconds are defaulted to 0).
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 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:
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: 123 have 7,8, and 0 for the data
Enter the second Timer object: 456 fields hours, minutes, and
Enter the third Timer object: 78-1 seconds since -1 is invalid.
The total number of hours is 12
The total number of minutes is 15
(sum of 1,4 and 7)
The total number of seconds is 9
(sum of 2,5, and 8)
(sum of 3,6 and 0)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Aided Database Design

Authors: Antonio Albano, Valeria De Antonellis, A. Di Leva

1st Edition

0444877355, 978-0444877352

More Books

Students also viewed these Databases questions

Question

static int help ( int N ) { if ( N Answered: 1 week ago

Answered: 1 week ago