For all those students who didn't attend class today :)
OOP – Creating a Class Exercise 2
Create the following class and its fields, properties, constructors, and methods. The Time class is used to
represent duration of time in hours, minutes, and seconds.
STEP 1: Create the Time class
STEP 2: Define the fields
STEP 3: Define the properties
STEP 4: Define the constructors (null and with arguments)
STEP 5: Time class should have at least the following methods:
A method to show the information in the following format: hh:mm:ss
A method to add seconds into the Time. For example: 01:02:03 plus 12 seconds is equal to
01:02:15.
A method to find the sum of two Time values. For example: 01:02:03 plus 11:22:33 is equal to
12:24:36.
A method to check if two Time values are equal. For example: 01:02:03 and 01:02:03 are equal.
STEP 6: Create the user interface (form) where a user can input the hours, minutes, and
seconds, display the information in presentable format (hh:mm:ss), find the sum of two
Time values, add seconds into the Time, and compare two Time values.
STEP 7: Consider the following scenario and modify the specification of Time class if
necessary:
Can the hours, minutes, and seconds be negative values?
Are there maximum and minimum values for hours, minutes, and seconds?
How many different ways are there to create a Time object? Can the Time object be
created by specifying only the hours and/or the minutes?
What happens when you add some seconds into a Time value and the seconds part
of the Time value exceeds 59 seconds? For example: Should the result of this
operation (01:00:59 plus 2 seconds) be 01:00:61 or 01:01:01?
What happens when you add two Time values and the minutes and seconds part of
the Time value exceeds 59? For example: Should the result of this operation
(01:50:50 plus 02:20:30) be 03:70:80 or 04:11:20?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment