Package model

Class Deck

java.lang.Object
model.Deck

public class Deck extends Object

Holds multiple Card objects and performs operations such as shuffling the deck.

This class is responsible for creating a deck, populating it with 52 cards, shuffling the deck, adding cards to the deck, removing a card from the deck, checking if the deck has any cards left, emptying the deck, and returning the deck's current size.

Author:
Michael Neuper michael@michaelneuper.com
  • Constructor Details

    • Deck

      public Deck()
      Constructs a new empty Deck object.
  • Method Details

    • populate

      public void populate()
      Populates empty Deck with 52 Card objects by looping over each Card.Rank and the value of its Card.Suit.
    • shuffle

      public void shuffle()
      Shuffles Deck using a temporary Deck for storing cards in random order.
    • addCard

      @Deprecated public void addCard(Card inCard)
      Deprecated.
      Adds a Card to the Deck.
      Parameters:
      inCard - the Card the be added to the deck
    • takeCard

      public Card takeCard()
      Takes copy of first Card from the Deck and removes it.
      Returns:
      the Card that was removed
    • hasCards

      public boolean hasCards()
      Checks whether the Deck to hit is populated with Card objects.
      Returns:
      true if the Deck has Cards in, false otherwise
    • emptyDeck

      public void emptyDeck()
      Removes all Card objects from the Deck.
    • addCards

      public void addCards(ArrayList<Card> cards)
      Adds an ArrayList of Card objects to the Deck.
      Parameters:
      cards - the ArrayList of Card objects to be added to Deck
    • getCards

      public ArrayList<Card> getCards()
      Returns an ArrayList containing all the Card objects in the Deck.
      Returns:
      the ArrayList with the cards in the Deck
    • reloadDeckFromDiscard

      public void reloadDeckFromDiscard(Deck discard)
      Take all cards from discarded deck and place them in this deck, shuffled. Clear the old deck.
      Parameters:
      discard - the deck cards are coming from
    • cardsLeft

      public int cardsLeft()
      Returns:
      number of cards left in the deck.
    • toString

      public String toString()
      Returns a String representation of the Deck object. The String contains a list of all the cards in the deck, with each card on a new line.
      Overrides:
      toString in class Object
      Returns:
      a String representation of the Deck object