I'm making a card game and I found useful to include a 60 second countdown timer. Here is my approach:
import java.util.Timer;
import java.util.TimerTask;
public class SecondTimer {
private Timer timer;
private int countDown;
private int secondsLeft;
public SecondTimer() {
timer = new Timer();
}
public void reset() {
secondsLeft = countDown;
// Decrease seconds left every 1 second.
timer.schedule(new TimerTask() {
@Override
public void run() {
secondsLeft--;
if (secondsLeft == 0) {
timer.cancel();
}
}
}, 0, 1000);
}
public void setCountDown(int seconds) {
this.countDown = seconds;
}
public int getSecondsLeft() {
return secondsLeft;
}
}
Is this considered clean? How can I test such classes?