Skip to content

Exercise_16_20 and Exercise_15_32 #13

Open
@csv77

Description

@csv77

Hi!
I found some bug in StopWatch class's run method (Exercise_16_20). The code is:

protected void run() {
		if (minute == 59)
			hour = hour + 1; 

		if (second == 59) 
		  minute = minute + 1;

		second = second < 59 ? second + 1 : 0;

		text.setText(getTime());
}

This code segment will be invoked every second. It means for example, if the minute variable reaches 59, then every second the hour will be incremented (so in 10 second 10 times). The minute variable can be higher than 59, it is also unusual. It can be tested, if you set the Duration.millis to a low value, f.e. to 10ms. I think the code below could work better:

protected void run() {
        if(min == 59 && sec == 59) {
            hour++;
            min = 0;
            sec = 0;
        }
        if(sec == 59 && min != 59) {
            min++;    
        }
        sec = (sec < 59 ? sec + 1 : 0);
        text.setText(getTime());
}

The same problem is with the method moveClock() in Exercise_15_32 in ClockPane class. It could be modified similarly.
Bye,
Csaba

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions