import java.util.ArrayList; import java.util.Random; public class Deck { private ArrayList cards; public Deck() { cards = new ArrayList<>(); } public ArrayList getCards() { return cards; } public Card deal() { return cards.remove(0); } public int getScore() { int points = 0; for (Card c : cards) { switch (c.getValue()) { case 1: // an ace counts as 11 by default points += 11; break; case 11: case 12: case 13: // face cards count as 10 points += 10; break; default: points += c.getValue(); } } // try to lower score with aces going 11->1 if (points > 21) { for (Card c : cards) { if (c.getValue() == 1) { points -= 10; if (points <= 21) { break; } } } } return points; } public void buildStandardDeck() { for (Suit s : Suit.values()) { for (int val = 1; val <= 13; val++) { cards.add(new Card(s, val)); } } } public void shuffle() { Random rng = new Random(); ArrayList newCards = new ArrayList<>(); while (!cards.isEmpty()) { // pick random card from orginal deck int index = rng.nextInt(cards.size()); Card c = cards.remove(index); newCards.add(c); } cards = newCards; } public void print() { for (Card c : cards) { System.out.println(c); } } }