com.gbayer.basicblackjack
Class Hand

java.lang.Object
  extended by com.gbayer.basicblackjack.Hand

public class Hand
extends java.lang.Object

A Hand contains Cards currently held by a Player


Nested Class Summary
static class Hand.Result
          The Enum Result.
 
Field Summary
static int ACE_UPGRADE_VALUE
          Constant - Difference between low and high value of an ace.
static int MAX_HAND_VALUE
          Constant - Highest value a hand can have before busting.
 
Constructor Summary
Hand()
          Instantiates a new hand.
 
Method Summary
 void addCard(Card card)
          Adds a card to the hand.
 void clear()
          Clear all cards in hand.
 int getTotalHandValue()
          Calculates total hand value.
 java.lang.String toString()
          Generates string representing all cards in the hand.
 java.lang.String toStringShowingTopCardOnly()
          Generates string showing top card in hand openly and all others as X (face down).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_HAND_VALUE

public static final int MAX_HAND_VALUE
Constant - Highest value a hand can have before busting.

See Also:
Constant Field Values

ACE_UPGRADE_VALUE

public static final int ACE_UPGRADE_VALUE
Constant - Difference between low and high value of an ace.

See Also:
Constant Field Values
Constructor Detail

Hand

public Hand()
Instantiates a new hand.

Method Detail

addCard

public void addCard(Card card)
Adds a card to the hand.

Parameters:
card - the card

clear

public void clear()
Clear all cards in hand. Hand will be empty. Underlying data structure is reused.


getTotalHandValue

public int getTotalHandValue()
Calculates total hand value. Counts ace as 11 when possible without causing hand to bust.

Returns:
the total hand value

toString

public java.lang.String toString()
Generates string representing all cards in the hand.

Overrides:
toString in class java.lang.Object

toStringShowingTopCardOnly

public java.lang.String toStringShowingTopCardOnly()
Generates string showing top card in hand openly and all others as X (face down).

Returns:
the string