Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercise_16_20 and Exercise_15_32 #13

Open
csv77 opened this issue Apr 26, 2017 · 0 comments
Open

Exercise_16_20 and Exercise_15_32 #13

csv77 opened this issue Apr 26, 2017 · 0 comments

Comments

@csv77
Copy link

csv77 commented Apr 26, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant