Class Hand
- java.lang.Object
-
- Hand
-
public class Hand extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description Hand()
Create a hand that is initially empty.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCard(Card c)
Add a card to the hand.void
clear()
Remove all cards from the hand, leaving it empty.Card
getCard(int position)
Gets the card in a specified position in the hand.int
getCardCount()
Returns the number of cards in the hand.void
removeCard(int position)
Remove the card in a specified position from the hand.void
removeCard(Card c)
Remove a card from the hand, if present.void
sortBySuit()
Sorts the cards in the hand so that cards of the same suit are grouped together, and within a suit the cards are sorted by value.void
sortByValue()
Sorts the cards in the hand so that cards of the same value are grouped together.
-
-
-
Method Detail
-
clear
public void clear()
Remove all cards from the hand, leaving it empty.
-
addCard
public void addCard(Card c)
Add a card to the hand. It is added at the end of the current hand.- Parameters:
c
- the non-null card to be added.- Throws:
java.lang.NullPointerException
- if the parameter c is null.
-
removeCard
public void removeCard(Card c)
Remove a card from the hand, if present.- Parameters:
c
- the card to be removed. If c is null or if the card is not in the hand, then nothing is done.
-
removeCard
public void removeCard(int position)
Remove the card in a specified position from the hand.- Parameters:
position
- the position of the card that is to be removed, where positions are starting from zero.- Throws:
java.lang.IllegalArgumentException
- if the position does not exist in the hand, that is if the position is less than 0 or greater than or equal to the number of cards in the hand.
-
getCardCount
public int getCardCount()
Returns the number of cards in the hand.
-
getCard
public Card getCard(int position)
Gets the card in a specified position in the hand. (Note that this card is not removed from the hand!)- Parameters:
position
- the position of the card that is to be returned- Throws:
java.lang.IllegalArgumentException
- if position does not exist in the hand
-
sortBySuit
public void sortBySuit()
Sorts the cards in the hand so that cards of the same suit are grouped together, and within a suit the cards are sorted by value. Note that aces are considered to have the lowest value, 1.
-
sortByValue
public void sortByValue()
Sorts the cards in the hand so that cards of the same value are grouped together. Cards with the same value are sorted by suit. Note that aces are considered to have the lowest value, 1.
-
-