- #1
stonecoldgen
- 109
- 0
I have 2 possibilities, non of them worked:
PD: I am sure that all the methods inside this method(s) are correct and I am sure that the program's GUI is refreshing effectively.
PD: I am sure that all the methods inside this method(s) are correct and I am sure that the program's GUI is refreshing effectively.
Code:
public void metodo1()
{
for (int i=0; i<(perros.size()); i++){
for (int j=perros.size()-1; j>0; j--){
Perro perro2=(Perro)perros.get(j);
int pts2=perro2.darPuntosObediencia();
Perro perro3=(Perro)perros.get(j-1);
int pts3=perro3.darPuntosObediencia();
if(pts2<pts3){
perros.set((j-1), perro2);
perros.set(j, perro3);
}
}
}
}
Code:
public void metodo1()
{
for (int j=0; j<(i-1); j++){ //empieza a la izquierda del arayList, ascendiendo hasta la posicion i-1
Perro perroIzquierda=(Perro)perros.get(j); //lo mismo para el del indice j
int ptsIzquierda=perroIzquierda.darPuntosObediencia();
Perro perroMitad=(Perro)perros.get(j+1);
int ptsMitad=perroMitad.darPuntosObediencia();
if(ptsMitad<ptsIzquierda){ //si se da esta condicion:
perros.set ((j+1), perroIzquierda); //el perro de la izquierda sube una posicion
}
}
}