The problem I'm having is the following: I'm modeling a basketball team with some functions like agaregarTitular()
and agregarSuplente()
. Now I want to implement the cambiarSuplenteComoTitular()
method, for that I defined 2 arrays of type Jugador
; one of substitutes and one of substitutes but, once I make the change, I need to eliminate the player who changes the substitution arrangement; but I do not know how to do it.
public class Equipo{
private String nombre;
private int a=0;
private int b=0;
Jugador cambio;
private Jugador titulares[];
private Jugador suplentes[];
public Equipo(String nombre, int ntitulares, int nsuplentes){
this.nombre=nombre;
try{
if(ntitulares+nsuplentes==30){
titulares=new Jugador[ntitulares];
suplentes=new Jugador[nsuplentes];
}}
catch(ArrayIndexOutOfBoundsException ex){
System.out.println("Error 0");
}
}
public String getNombre(){
return nombre;
}
public void dimeNombre(String nombre){
this.nombre=nombre;
}
public void agregarTitular(Jugador j){
for(int i=0;i<titulares.length;i++){
if(titulares[i]==null){
titulares[i]=j;
}
}
}
public void agregarSuplente(Jugador j){
for(int i=0;i<suplentes.length;i++){
if(suplentes[i]==null){
suplentes[i]=j;
}
}
}
public boolean cambiarSuplenteComoTitular(long ncedula){
boolean traspaso=false;
for(int i=0;i<suplentes.length;i++){
if(suplentes[i].getCedula()==ncedula){
cambio=suplentes[i];
agregarTitular(cambio);
traspaso=true;
}else{
traspaso=false;
}
}
return traspaso;
}