how can I add the common values of an ArrayListString in Java?

1
public class Inicio {
    public static void main(String[] args) {
        ArrayList<String> lanzadas = new ArrayList<String>();
        int opcion = 0;
        int totalCara = 0;
        int totalCruz = 0;
        Scanner entrada = new Scanner(System.in);
       do{
           System.out.println();
           System.out.println("Bienvenido, ¿Que desea hacer?\n");
           System.out.println("\t1. Lanzar Moneda\n");
           System.out.println("\t2. Mostrar Resultados\n");
           System.out.println("\t3. Salir\n");
           opcion = entrada.nextInt();
           switch(opcion){
               case 1:{
                   System.out.println();
                   Moneda moneda = new Moneda();
                   moneda.tirar();
                   if(moneda.getValorCara()%2 == 1){
                       lanzadas.add ("Cara");
                       System.out.println(false);
                   }else if(moneda.getValorCara()%2 == 0){
                       lanzadas.add("Cruz");
                       System.out.println(true);
                   }
                   break;
               }
               case 2:{
                   System.out.println();
                   System.out.printf("%s\t%s\n", "Lugar", "Lado");
                   System.out.println("----------------------------");
                   for (int i = 0; i < lanzadas.size(); i++) {
                       System.out.printf("%d\t%s\n", i, lanzadas.get(i));
                       System.out.println("___________________");
                    }
                   for (int i = 0; i < lanzadas.size(); i++) {

                   }
                   break;
               }
               default:{
                   System.out.println("Esa opcion no existe");   
               }
           }
       }while(opcion != 3);
    }
}

I want to add the face values and cross values and how many times did each one come out, please

    
asked by Alex Reyes 20.03.2017 в 05:38
source

1 answer

0

Increase the value of your variables once you take out heads or tails

Moneda moneda = new Moneda();
moneda.tirar();
if(moneda.getValorCara()%2 == 1){
    lanzadas.add ("Cara");
    System.out.println(false);
    totalCara++;

}else if(moneda.getValorCara()%2 == 0){
    lanzadas.add("Cruz");
    System.out.println(true);
    totalCruz++;
}

And in the case that shows the results you get the information of those two variables

    int totalCara
    int totalCruz
    
answered by 20.03.2017 / 08:06
source