Define a class named Timespan. A TimeSpan object stores a span of time in hours and minutes (for example, the time span between Monday 8AM and Wednesday 10:30AM is 50 hours, 30 minutes). Each TimeSpan object should have the following public methods:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Define a class named TimeSpan. A TimeSpan object stores a span of time in hours and
minutes (for example, the time span between Monday 8AM and Wednesday 10:30AM is
50 hours, 30 minutes). Each TimeSpan object should have the following public methods:
00000
TimeSpan (hours, minutes)
Constructs a Timespan object storing the given time span of minutes and seconds.
add (hours, minutes)
Adds the given amount of time to the current time span (e.g. 2 hours, 15 min + 1 hour, 45 min = 4 hours).
Assume that the arguments 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 "28h4 6m".
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. For example, consider the following code:
TimeSpan tl = new TimeSpan (3, 45);
System.out.println (tl + " is " + t1.getTotalHours () +
t1.add (2, 30);
System.out.println (tl +
TimeSpan t2
t1.add (t2);
System.out.println (t1 +
hours");
" is " + tl1.getTotalHours () + " hours");
= new TimeSpan (0, 55);
is
+ t1.getTotalHours () + " hours");
This code creates a Timespan object and adds three different times to it. The output should be:
3h45m is 3.75 hours
6h15m is 6.25 hours
7h10m is 7.166666666666667 hours
Notice that the second time is not 5 hours, 75 minutes, although that's what you'd get by just adding values.
Transcribed Image Text:Define a class named TimeSpan. A TimeSpan object stores a span of time in hours and minutes (for example, the time span between Monday 8AM and Wednesday 10:30AM is 50 hours, 30 minutes). Each TimeSpan object should have the following public methods: 00000 TimeSpan (hours, minutes) Constructs a Timespan object storing the given time span of minutes and seconds. add (hours, minutes) Adds the given amount of time to the current time span (e.g. 2 hours, 15 min + 1 hour, 45 min = 4 hours). Assume that the arguments 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 "28h4 6m". 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. For example, consider the following code: TimeSpan tl = new TimeSpan (3, 45); System.out.println (tl + " is " + t1.getTotalHours () + t1.add (2, 30); System.out.println (tl + TimeSpan t2 t1.add (t2); System.out.println (t1 + hours"); " is " + tl1.getTotalHours () + " hours"); = new TimeSpan (0, 55); is + t1.getTotalHours () + " hours"); This code creates a Timespan object and adds three different times to it. The output should be: 3h45m is 3.75 hours 6h15m is 6.25 hours 7h10m is 7.166666666666667 hours Notice that the second time is not 5 hours, 75 minutes, although that's what you'd get by just adding values.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
void method
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education