0

So I have a problem where I'm getting a Time type as an input(time). I also receive a number of seconds to increment that time by(seconds).

In the first few lines before you see me reference the this variable I am taking the seconds and creating integers to fill in the new time object I'll be incrementing the original time input by.

When watching the debugger I also notice time and my variable this are referencing the same object. So there is a problem with my assignments this.second = (time.second + sum.second); and the other two this's as well.

Before I added the next few assignments with the this.minute = (int)(this.second / 60); this.second = Math.abs((int)(this.second % 60)); and other 3 this assignments I was getting negatives for my values. After adjusting values with the Math.abs part I'm now seeing the assignments turn to 00:00: for everything once I hit this.hour and this.minute assignments. The same for the last assignment of this.hour.

I'm not sure why the value is changing the whole time variable when I am specifying specific places for it to change.

public void incrementJaret(Time time, double seconds)
{
    double minutes;
    double hours;
    double days;
    
    Time sum = new Time();
    
    minutes = (seconds / 60);
    sum.second = Math.abs((int)(seconds % 60));

    hours = (minutes / 60);
    sum.minute = Math.abs((int)(minutes % 60));

    days = (hours / 24);
    sum.hour = Math.abs((int)(hours % 24));
    
    this.second = (time.second + sum.second);
    
    this.minute = (time.minute + sum.minute);
    
    this.hour = (time.hour + sum.hour);
    
    this.minute = (int)(this.second / 60);
    this.second = Math.abs((int)(this.second % 60));

    this.hour = (int)(this.minute / 60);
    this.minute = Math.abs((int)(this.minute % 60));

    days = (int)(this.hour / 24);
    this.hour = Math.abs((int)(days % 24));
}

0 Answers0