// Deck.java import java.util.ArrayList; import java.util.Random; public class Deck { private ArrayList cards; public Deck() { cards = new ArrayList<>(); } public void add52() { for (Suit s : Suit.values()) { for (int v = 2; v <= 14; v++) { cards.add(new Card(s, v)); } } } public Card deal() { // return the top card, if there is one if (cards.size() == 0) { return null; } else { Card top = cards.get(0); cards.remove(0); return top; } } public void shuffle() { Random rng = new Random(); ArrayList shuffled = new ArrayList<>(); while (cards.size() > 0) { // pick a random card int index = rng.nextInt(cards.size()); Card c = cards.get(index); // remove it from old deck cards.remove(index); // add it to new, shuffled deck shuffled.add(c); } cards = shuffled; } public void print() { for (Card c : cards) { System.out.println(c); } } }