import java.util.ArrayList; import java.util.Random; public class Deck { private ArrayList cards; public Deck(boolean empty) { cards = new ArrayList<>(); if (!empty) { // for each suit for (Suit s : Suit.values()) { for (int rank = 2; rank <= 14; rank++) { cards.add(new Card(s, rank)); } } } } public void print() { for (int i = 0; i < cards.size(); i++) { System.out.println((i + 1) + ". " + cards.get(i)); } } public int getSize() { return cards.size(); } public void add(Card c) { cards.add(c); } // get & remove a card by index public Card take(int index) { return cards.remove(index); } // just view a card public Card get(int index) { return cards.get(index); } // return & remove the top card public Card deal() { return cards.remove(cards.size() - 1); } public void shuffle() { ArrayList newCards = new ArrayList<>(); Random rng = new Random(); while (cards.size() > 0) { int index = rng.nextInt(cards.size()); Card c = cards.get(index); newCards.add(c); cards.remove(index); } cards = newCards; } }