import java.util.ArrayList; import java.util.Random; public class Deck { private ArrayList cards; private static final String[] values = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"}; public Deck() { cards = new ArrayList<>(); } public void buildStandardDeck() { for (Suit s : Suit.values()) { for (String val : values) { cards.add(new Card(s, val)); } } } // remove one card from deck and return it public Card deal() { if (cards.isEmpty()) { throw new IllegalStateException("Cannot deal from empty deck"); } Card c = cards.remove(0); return c; } // add a card into the deck public void add(Card c) { cards.add(0, c); } public void shuffle() { Random rng = new Random(); for (int i = 0; i < cards.size() * 10; i++) { int index = rng.nextInt(cards.size()); Card c = cards.remove(index); index = rng.nextInt(cards.size()); cards.add(index, c); } } public Card get(int index) { return cards.get(index); } public void print() { for (Card c : cards) { System.out.println(c); } } }