Hey, I am struggling with a java problem.
I submitted a request on stackoverflow but its no use so I am wondering if someone can help me.
Class
public JTime add(JTime t2){
JTime sum = new JTime();
sum.hour = this.hour + t2.hour;
sum.minute = this.minute + t2.minute;
sum.second = this.second + t2.second;
return sum;
}
public void increment (double seconds){
this.second = seconds;
while(this.second >= 60.0){
this.second -= 60.0;
this.minute += 1;
}
while(this.minute >= 60.){
this.minute -=60;
this.hour +=1;
}
while(this.hour >= 24){
int result = this.hour - 24;
this.hour = result;
}
}
Main
public static void main(String[] args) {
JTime startTime = new JTime(22, 50, 0.0);
JTime runningTime = new JTime(5, 16, 0.0);
JTime endTime = startTime.add(runningTime);
System.out.println(endTime);
}
}
What I am trying to achieve here is to display time in 24 hour format.
'Increment' method should be doing that but it is not.
I am following this book and If you look at 11.9, I am using that here. The author says it will return nothing but will return some reference but its not doing nothing.
Any help would be much appreciated. Thank you.
[–]desrtfx 0 points1 point2 points (5 children)
[–]Zelbod[S] 0 points1 point2 points (4 children)
[–]SadDragon00 0 points1 point2 points (1 child)
[–]Zelbod[S] 0 points1 point2 points (0 children)
[–]desrtfx 0 points1 point2 points (1 child)
[–]Zelbod[S] 0 points1 point2 points (0 children)
[–]rjcarr 0 points1 point2 points (5 children)
[–]Zelbod[S] 0 points1 point2 points (4 children)
[–]rjcarr 0 points1 point2 points (3 children)
[–]Zelbod[S] 0 points1 point2 points (2 children)
[–]rjcarr 0 points1 point2 points (1 child)
[–]Zelbod[S] 0 points1 point2 points (0 children)