Java Exercise Help Feedback Greatly Appreciated 1 Create Tostring Method Following Code Re Q43880411
Java Exercise Help!
Any feedback is greatly appreciated
1. Create a “toString()” method for the following code.
// Represents a time span of hours and minutes elapsed.
// Class invariant: minutes < 60
public class TimeSpan {
private int hours;
private int minutes;
// Constructs a time span with the giveninterval.
// pre: hours >= 0 && minutes>= 0
public TimeSpan(int hours, int minutes) {
this.hours = 0;
this.minutes = 0;
add(hours,minutes);
}
// Adds the given interval to this timespan.
// pre: hours >= 0 && minutes>= 0
public void add(int hours, int minutes) {
this.hours +=hours;
this.minutes +=minutes;
// convert each 60minutes into one hour
this.hours +=this.minutes / 60;
this.minutes =this.minutes % 60;
}
}
2. Write a Java client code that implements the following:
- Create two TimeSpan objects with any hour and minute value
- Print out current time
- Add some hours and minutes to two TimeSpan objects
- Print out current time again
Expert Answer
Answer to Java Exercise Help! Any feedback is greatly appreciated 1. Create a “toString()” method for the following code. // R…
OR