0

I'm trying to do a Blackjack game but I don't know how to change the value of "ACE" to 1 if 11 is too high. I'm now trying to search a Arraylist for A's to change the value of one ore more of them. But how can I see how much A's are in my Arraylist?

      while (getPointsPC() < 17 || getPointsPC() < getPointsPL()){

            int acees = 0;

            random = bj.getRandom();
            CardsPC.add(bj.getCard(random));
            setPointsPC(random);

            lblPointsPC.setText("Points Dealer: " + Integer.toString(getPointsPC()));

            String text = CardsPC.get(0);
            for(int i = 1; i < CardsPC.size(); i++){
                text = text + ", " + CardsPC.get(i);
            }

            if (CardsPC.contains("A") && getPointsPC() > 21 && acees < CardsPC.**HOW_MUCH_A's???**){
                setPointsPC(13);
                acees++;
            }

            lblCardsPC.setText(text);

        }
  • 2
    I didn't know "[ASS](https://c1.staticflickr.com/3/2651/3892880140_52ec991129.jpg)" had a number. Did you mean "ACE"? – Andreas Jun 06 '16 at 07:51

1 Answers1

0

Is your CardsPC is your mentioned ArrayList? Just set counter variable:

String text = "";
int counter = 0;
for(int i = 0; i < CardsPC.size(); i++){
     text = text + (i > 0 ? ", " : "") + CardsPC.get(i);
     if (CardsPC.get(i).contains("A")) { // or use equals, base on your input.
          counter++;
          // do something with found "A" element if you want.
     }
}
Nam Tran
  • 643
  • 4
  • 14