0
Good morning, I’m trying to create a basketball scoreboard to start learning programming in java/android studio.
I have created a class for the game time clock called timer that is working very well. Now I want to extend this class to create the shootclock (it is the clock that counts the possession of the ball, it rotates along with the scoreboard, but has only 24 seconds.)
Since the whole implementation is the same, I decided to extend it to the Shootclock() class and just override the visualization method and the constructor so it has only 24 seconds. However, I am trying to create an override for the update methodContagem(){}, which displays the time on the scoreboard, but I cannot pull the mother class variables.
That’s the mother class method.
public void atualizarContagem() {
int minutes = (int) (tempoAteAcabar / 1000) / 60;
int seconds = (int) (tempoAteAcabar / 1000) % 60;
tempoAteAcabarFormatado = String.format(Locale.getDefault(),"%02d:%02d", minutes, seconds);
tempoPartida.setText(tempoAteAcabarFormatado);
}
At first I thought I could solve by just changing the code. But obviously I didn’t understand how the syntax works at the time
public void atualizarContagem() {
int seconds = (int) (super.tempoAteAcabar / 1000) % 60;
tempoAteAcabarFormatado = String.format(Locale.getDefault(),"%02d:%02d", seconds);
tempoPartida.setText(tempoAteAcabarFormatado);
}
I didn’t quite understand your problem, but at first, the Timer class should (or should) have a method, I don’t know,
countdown(int seconds)
, where you would spend the amount of seconds. Then just pass the equivalent in seconds for the duration of the match (or the fourth) and, in another call, the 24 seconds of possession of the ball. All this to say that you do not need to create different objects and logics to deal with apparently two identical problems.– StatelessDev
I fully agree with @Statelessdev. You don’t need to have an accountant for everything, a generic accountant already solves everything.
– Gustavo