-3

I'm on a university project in java. And I've got a problem. I'm doing a poker game simulation, and i have an arraylist called mano that has atributes "figura" and "palo" on every position. And another array Figura[] that has 5 figures. I want to compare the figures with the figures in the arraylist mano and when there are 5 equals, I want the programm to return me a premioPoker = true. But I get an error and when I execute the project and I don't know what's wrong.

String figura[]={"As","Dos","Sota","Caballo","Rey"};
boolean premioPoker = false;

static boolean poker(String figura[], ArrayList<Carta> mano){
    boolean premioPoker=false;
    int contadorPoker=0;
    int contadorMano;
    int contadorFigura=0;
    do {//contadorMano=0;
        do{                           
             //creo un contador
            contadorMano=0;                
                if (figura[contadorFigura].equals(mano.get(contadorMano).getFigura())){ //si la figura es igual a alguna de las almacenadas en la mano, lo contamos
                    contadorPoker++;
                }                   
                    contadorMano++;                                                             
            if (contadorPoker==4) {
                premioPoker=true;
            }
        contadorFigura++;
        contadorPoker=0;
        }while(contadorMano<5 && contadorPoker<4);
    }while (contadorFigura<5 && (!premioPoker));

    return premioPoker;

}

1 Answers1

0

You may use ArrayList's containsAll method:

static boolean poker(String figura[], ArrayList<Carta> mano) {
    ArrayList<String> figuraList = Arrays.asList(figura);
    ArrayList<String> manoFiguras = new ArrayList<>;
    for (Carta carta: mano)
        manoFiguras.add(carta.getFigura());
    return figuraList.containsAll(manoFiguras);
}

If you need them in specified order you should use equals instead of containsAll

Lega
  • 88
  • 8