Class Deck
java.lang.Object
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
-
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.
-
Constructor Details
-
Deck
Creates a newDeck
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
Deals a card from this deck.- Returns:
- the card just dealt, or null if all the cards have been previously dealt.
-
toString
Generates and returns a string representation of this deck.
-