------Define a class named TimeSpan. A TimeSpan object stores a span of time in hours and minutes (for example, the time span between 8:00am and 10:30am is 2 hours, 30 minutes). Each TimeSpan object should have the following public methods:
TimeSpan(hours, minutes)
Constructs a TimeSpan object storing the given time span of minutes and seconds.
getHours()
Returns the number of hours in this time span.
getMinutes()
Returns the number of minutes in this time span, between 0 and 59.
add(hours, minutes)
Adds the given amount of time to the span. For example, (2 hours, 15 min) + (1 hour, 45 min) = (4 hours). Assume that the parameters are valid: the hours are non-negative, and the minutes are between 0 and 59.
add(timespan)
Adds the given amount of time (stored as a time span) to the current time span.
getTotalHours()
Returns the total time in this time span as the real number of hours, such as 9.75 for (9 hours, 45 min).
toString()
Returns a string representation of the time span of hours and minutes, such as "28h46m".--------
Znam da je rešenje u javi otprilike ovakvo:
public class TimeSpan {
private int hours;
private int minutes;
// Constructs a time span representing the given number of hours and minutes.
public TimeSpan(int initialHours, int initialMinutes) {
hours = 0;
minutes = 0;
add(initialHours, initialMinutes);
}
// Adds the given hours/minutes to this time span, wrapping hours if necessary.
public void add(int initialHours, int initialMinutes) {
hours += initialHours;
minutes += initialMinutes;
if (minutes >= 60) {
minutes -= 60; // convert 60 min --> 1 hour
hours++;
}
}
// Adds the given hours/minutes to this time span, wrapping hours if necessary.
public void add(TimeSpan span) {
add(span.hours, span.minutes);
}
// Returns the total hours represented by this time span,
// such as 7.75 for 7 hours, 45 minutes.
public double getTotalHours() {
return hours + minutes / 60.0;
}
// Returns a text representation of this time span, such as "7h45m".
public String toString() {
return hours + "h" + minutes + "m";
}
}
"You're gettin' the fuck...
I know you're seven !"
"But you'll be a seven year old
walkin' the dog no house motherfucker !"