Define a class named TimeSpan. A TimeSpan object stores a span of time in hours and minutes (for example, the time span between 6:00am and 8:30am is 2 hours, 30 minutes). Each TimeSpan object should have the following public methods
Define a class named TimeSpan. A TimeSpan object stores a span of time in hours and minutes (for example, the time span between 6:00am and 8:30am is 2 hours, 30 minutes). Each TimeSpan object should have the following public methods
· TimeSpan(hours, minutes)
o Constructs a TimeSpan object storing the given time span of hours and minutes.
· getHours()
o Returns the number of hours in this time span.
· getMinutes()
o Returns the number of minutes in this time span, between 0 and 59.
· add(hours, minutes)
o Adds the given amount of time to the span. For example, (1 hours, 15 min) + (2 hour,15 min) = (3 hours 30 min). Assume that the parameters are valid: the hours are nonnegative, and the minutes are between 0 and 59.
· add(TimeSpan)
o Adds the given amount of time (stored as a time span) to the current time span.
· getTotalHours()
o Returns the total time in this time span as the real number of hours, such as 9.75 for (9 hours, 45 min).
· toString()
o Returns a string representation of the time span of hours and minutes, such as "28h46m". The minutes should always be reported as being in the range of 0 to 59. That means that you may have to "carry" 60 minutes into a full hour.
Step by step
Solved in 3 steps with 1 images