Circular Tally Counter Not Rolling Over
Posted
by
chris ward
on Stack Overflow
See other posts from Stack Overflow
or by chris ward
Published on 2012-09-05T21:27:10Z
Indexed on
2012/09/05
21:38 UTC
Read the original article
Hit count: 211
I was practicing my java and was trying to make a simple counter with rollover at max, but for some reason it isn't rolling over. Any advice?
public class HandTallyCounter {
private int max;
private int count;
public HandTallyCounter(int max) {
this.max = max;
count = 0;
}
public void click() {
if (count++ > max) {
count = 0;
}
}
public int getCount() {
return count;
}
public void reset() {
count = 0;
}
}
© Stack Overflow or respective owner