If you don\'t test your answer and make sure it works. Please don\'t take my poi
ID: 3533072 • Letter: I
Question
If you don't test your answer and make sure it works. Please don't take my points!!!!
Description:
This assignment will test your understanding of classes.
Write a class called Time that can be used to store a time in hours, minutes and seconds. It should have the following
public methods:
Time() A constructor that takes no parameters and that constructs an object
representing 0 time.
Time(int, int, int) A constructor that takes three integers (hours, minutes, seconds) and
that constructs a Time object storing that time.
void add(int, int, int) A method which takes a time as three integers (hours, minutes, seconds)
and that adds the time to the current time.
double getTime() A method which returns the time as the real-valued number of hours
with a decimal (as in 9.53).
String toString() toString which returns a string representation of the time (hh:mm:ss)
When converted to a string, the seconds and minutes should always be
reported as being in the range of 0 to 59. That means that you may have to
"carry" a full hour or minute to the next column.
For example, consider the following code:
Time t = new Time(3, 45, 15);
System.out.println(t + " equals " + t.getTime());
t.add(2, 30, 55);
System.out.println(t + " equals " + t.getTime());
t.add(0, 55, 45);
System.out.println(t + " equals " + t.getTime());
This code creates a Time object and adds three different times to it, each time reporting the time as a string and as a double. The
output should be:
3:45:15 equals 3.754166666666667
6:16:10 equals 6.269444444444445
7:11:55 equals 7.198611111111111
Notice that the second time is not reported as 5 hours, 75 minutes and 70 seconds, even though that's what you'd get by a simple
addition of values. You cannot create any additional methods other than those mentioned above. Write your solution in
Time.java and your main method in TimeMain.java
Explanation / Answer
Note: Text content in the code blocks is automatically word-wrappedRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.