public class Deck
extends java.lang.Object
| Modifier and Type | Field | Description |
|---|---|---|
private Card[] |
cards |
a card array that holds all of the cards in Deck
|
static int |
MAX_RANK_INT |
represents maximum integer value of rank
|
static int |
MAX_SUIT_INT |
represents maximum integer value of suit
|
static int |
MIN_RANK_INT |
represents minimum integer value of rank
|
static int |
MIN_SUIT_INT |
represents minimum integer value of suit
|
static int |
NUM_CARDS_FULL_DECK |
represents number of cards in a full deck
|
static int |
NUM_CARDS_SUIT |
represents number of cards in a suit
|
static Card[] |
sorted |
Holds the sorted Card array in the mergeSort methods
|
private int |
topCard |
the index of the top card of the deck;
for a full deck, it would be 51
|
| Constructor | Description |
|---|---|
Deck() |
Constructs a default Deck object that holds 52 cards that are sorted.
|
Deck(boolean sorted) |
Constructs a Deck object that holds 52 cards.
|
Deck(Card[] hands) |
Constructs a Deck object with a Card[]
|
| Modifier and Type | Method | Description |
|---|---|---|
Deck[] |
deal(int numHands,
int cardsPerHand) |
Deals a Deck
|
boolean |
equals(java.lang.Object other) |
Checks if this Deck is equal to the other Deck.
|
Card[] |
getCards() |
Returns the value of the Card[] that Deck holds
|
int |
getTopCard() |
Returns the index of the top card of the deck
|
private static void |
merge(Card[] temp,
int from,
int middle,
int to) |
Joins both sides of the array sent in back together.
|
void |
mergeSort() |
Uses the MergeSort method to sort the Cards in the Deck.
|
private static void |
mSort(Card[] temp,
int from,
int to) |
The recursive sort part of MergeSort.
|
Card |
pick() |
Returns and removes a random Card from the Deck
|
void |
selectionSort() |
Uses the SelectionSort method to sort the Cards in the Deck
|
void |
shuffle() |
Shuffles the card array in the Deck
|
java.lang.String |
toString() |
Returns the String value of the Deck object
|
private Card[] cards
private int topCard
public static final int MIN_SUIT_INT
public static final int MIN_RANK_INT
public static final int MAX_SUIT_INT
public static final int MAX_RANK_INT
public static final int NUM_CARDS_FULL_DECK
public static final int NUM_CARDS_SUIT
public static Card[] sorted
public Deck()
public Deck(boolean sorted)
sorted - if true, sorts the Card[], if false, shuffles the Card[]public Deck(Card[] hands)
hands - sets the array of Card to the passed arraypublic Card[] getCards()
public int getTopCard()
public void shuffle()
public java.lang.String toString()
toString in class java.lang.ObjectObject.toString()public boolean equals(java.lang.Object other)
equals in class java.lang.Objectother - the Deck object that this is being checked againstpublic Deck[] deal(int numHands, int cardsPerHand)
numHands - an integer that represents the number of hands to be dealtcardsPerHand - an integer that represents the card per hand that is dealtpublic Card pick()
public void selectionSort()
public void mergeSort()
private static void mSort(Card[] temp, int from, int to)
temp - array that references cards and thus changes cards when it is changedfrom - first index of given arrayto - last index of given arryprivate static void merge(Card[] temp, int from, int middle, int to)
temp - array that references cards and thus changes cards when it is changedfrom - first index of the given arraymiddle - middle index of the given arrayto - last index of the given array