   import java.util.*;
/**
 * A class that represents a player's hand
 * Uses a "parameterized" ArrayList (or in other words an ArrayList of Cards
 * @author - Nancy Harris, James Madison University
 * @version - 1.0
 */

    public class Hand
   {
   // specify that cards is an ArrayList of only Card objects
   // if generic object, then add method does not compile.
      private ArrayList<Card> cards;
   
   /** default constructor builds a hand of 5 cards
   */
       public Hand()
      {
      // this instantiates the ArrayList as a specific list of Cards
         cards = new ArrayList<Card>(5);// refer to page 406 in text
      }
   
   /**
   * Explicit constructor builds a hand of num cards
   *
   * @param num size of this Hand
   */
       public Hand(int num)
      {
      // this instantiates the ArrayList as a specific list of Cards
         cards = new ArrayList<Card>(num);
      }
   
   /** adds a card to this hand.  
   *  @param newCard The card object we are adding
   */	
       public void addCard(Card newCard) 
      {
         cards.add(newCard); // can always do this					
      }
   /** removeCard must first check to see if the specified Card object
   *   exists in the hand, then it can remove it.
   *
   *   @param awayCard Card object to be removed.
   *   @return 1 if the remove was successful, -1 otherwise.
   */
       public int removeCard(Card awayCard)
      {
         boolean empty   ;
         int     tempInt, returnValue ;
         Card    tempCard     ;
         empty = cards.isEmpty();// avoid exception - ensure non-empty hand
         returnValue = -1;
         if (!empty)
         {
            if(cards.contains(awayCard))
            {
               tempInt = cards.indexOf(awayCard);
               tempCard = cards.remove(tempInt);
               returnValue = 1;    			
            }	
         }
         return returnValue;
      }
   
   /** removeCard must first check to see if the specified Card object
   *   exists in the hand, then it can remove it.
   *   @param whichCard position of card to remove.
   *   @return 1 if the remove was successful, -1 otherwise.
   */
       public int removeCard(int whichCard)
      {
         Card  tempCard;
         int returnValue;
      
         if (cards.size() > whichCard)// avoiding exception
         {  
            returnValue = 1;
            tempCard = cards.remove(whichCard);
         }
         else
         {
            returnValue = -1;
         }	
         return returnValue;
      }
   
   /** display hand will run through all of the cards in the hand and using the toString
   *   method of the Card class, print the cards.
   */
       public void displayHand()
      {
       
         System.out.println (cards);
         for (int i = 0; i < cards.size(); i++)
         {
            System.out.println (cards.get(i));
         }
      
      }
   }