0
I am trying to create a class Balldefutebol that receives attributes of the class father Ball, the class ball possesses the attributes
private int ar = 100; //100%
private boolean furada = false;
Ball Class(does not have Imports):
public class Bola {
private int ar = 100;
private boolean furada = false;
public Bola() {
}
public Bola(int ar, boolean furada) {
this.ar = ar;
this.furada = furada;
}
public int getAr() {
return ar;
}
public void setAr(int ar) {
this.ar = ar;
}
public boolean isFurada() {
return furada;
}
public void setFurada(boolean furada) {
this.furada = furada;
}
}
Boladefutebol class(does not have Imports):
public class BolaDeFutebol extends Bola{
private String material = "Capotão";
private String esporte = "Futebol";
public BolaDeFutebol(String material, String esporte) {
super();
this.material = material;
this.esporte = esporte;
}
public BolaDeFutebol() {
}
public String getMaterial() {
return this.material;
}
public void setMaterial(String material) {
this.material = material;
}
public String getEsporte() {
return this.esporte;
}
public void setEsporte(String esporte) {
this.esporte = esporte;
}
public void Mostrar(){
System.out.println("Quantidade de ar: " + super.getAr() + "%");
System.out.println("Furada status: " + super.isFurada());
System.out.println("Material: " + getMaterial());
System.out.println("Esporte: " + getEsporte());
}
public void Mostrar(int ar){
System.out.println("Quantidade de ar: " + super.getAr() + "%");
}
public void Furar(){
setFurada(true);
int ar = getAr();
new Thread(){
@Override
public void run() {
for(int i = 0; i < ar; setAr(ar--)){
try {
Mostrar(ar);
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
super.run();
}
}.start();
}
}
Everything is working, but in this method(stick) of the class Boladefutebol I can not subtract the value of the attribute ar:
public void Furar(){
setFurada(true);
int ar = getAr();
new Thread(){
@Override
public void run() {
for(int i = 0; i < ar; setAr(ar--)){
try {
Mostrar(ar);
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
super.run();
}
}.start();
}
Every 1 second I want the ball to lose air, however, I can not change the value of the variable air, I’m a little rusty with superclasses in java I would like help and know where I am missing.
Test Class(does not have Imports):
public class UsaBola {
public static void main(String[] args) {
BolaDeFutebol bola = new BolaDeFutebol();
bola.Mostrar();
bola.Furar();
}
}
Thank you so much your answer helped me a lot to understand, I learned a lot from her
– Marcelo Henrique