Class Deck


public class Deck
extends Object
The Deck class represents a shuffled deck of cards. It provides several operations including initialize, shuffle, deal, and check if empty.
  • Constructor Summary

    Constructors 
    Constructor Description
    Deck​(String[] ranks, String[] suits, int[] values)
    Creates a new Deck instance.
    It pairs each element of ranks with each element of suits, and produces one of the corresponding card.
  • Method Summary

    Modifier and Type Method Description
    Card deal()
    Deals a card from this deck.
    boolean isEmpty()
    Determines if this deck is empty (no undealt cards).
    void shuffle()
    Randomly permute the given collection of cards and reset the size to represent the entire deck.
    int size()
    Accesses the number of undealt cards in this deck.
    String toString()
    Generates and returns a string representation of this deck.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Deck

      public Deck​(String[] ranks, String[] suits, int[] values)
      Creates a new Deck instance.
      It pairs each element of ranks with each element of suits, and produces one of the corresponding card.
      Parameters:
      ranks - is an array containing all of the card ranks.
      suits - is an array containing all of the card suits.
      values - is an array containing all of the card point values.
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Determines if this deck is empty (no undealt cards).
      Returns:
      true if this deck is empty, false otherwise.
    • size

      public int size()
      Accesses the number of undealt cards in this deck.
      Returns:
      the number of undealt cards in this deck.
    • shuffle

      public void shuffle()
      Randomly permute the given collection of cards and reset the size to represent the entire deck.
    • deal

      public Card deal()
      Deals a card from this deck.
      Returns:
      the card just dealt, or null if all the cards have been previously dealt.
    • toString

      public String toString()
      Generates and returns a string representation of this deck.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this deck.