// Note: This class uses "Javadoc" commenting formatting. You do not need to understand how // to format comments in this way. import java.util.ArrayList; import java.util.List; import java.util.Stack; /** * Represents a deck of Cards * @author Hunter Schafer, CSE 143 */ public class Deck { private Stack cards; /** * Constructs an empty deck of cards */ public Deck() { this(new ArrayList()); } // Constructs a deck with the given list of cards. // The order of the deck is determined by the order of the list, the first // card in the list is the top of the deck and the last card is the bottom. /** * Constructs a deck with the given list of cards. * The order of the deck is determined by the order of the list, the first * card in the list is the top of the deck and the last card is the bottom. * @param cards list of cards to build deck with */ public Deck(List cards) { this.cards = new Stack(); for (int i = cards.size() - 1; i >= 0; i--) { this.cards.push(cards.get(i)); } } /** * Returns if there are more cards in the deck * @return Returns true if there is another card in the deck, false otherwise */ public boolean hasNextCard() { return !this.cards.isEmpty(); } /** * Returns the card at the top of the deck. * @return the card at the top of the deck * @throws IllegalStateException if deck does not contain any cards */ public Card nextCard() { if (!this.hasNextCard()) { throw new IllegalStateException("No more cards in deck"); } return this.cards.pop(); } /** * Puts the given card at the top of the deck * @param card Card to be placed in deck */ public void putCard(Card card) { this.cards.push(card); } }