// Hunter Schafer, CSE 143 // This class represents a deck of cards import java.util.ArrayList; import java.util.List; import java.util.Stack; public class Deck { private Stack cards; // Constructs an empty deck 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. public Deck(List cards) { this.cards = new Stack(); for (int i = cards.size() - 1; i >= 0; i--) { this.cards.push(cards.get(i)); } } // Returns true if there is a card remaining in the deck, false otherwise. public boolean hasNextCard() { return !this.cards.isEmpty(); } // pre: The deck has another card, throws IllegalStateException otherwise // Returns the card at the top of the deck 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 public void putCard(Card card) { this.cards.push(card); } }