import java.io.BufferUnderflowException;
import java.util.ArrayList;

public class CardHolder
{
  protected ArrayList<Card> theCards[];
  protected int maxCards;//maximum sizeof the cardholder
  protected int numCards;//number of cards currently in the cardholder

  public CardHolder()
  {
    this.maxCards = max;
    this.theCards = new ArrayList<Card>();
    this.numCards = 0;
  }



/* theCards contains the address of an array of Cards.
Each element of that array can hold the address of a Card, but right
now, contains garbage;
*/

  public int getNumCards()
  {
    return this.numCards;
  }

  public int getMaxCards()
  {
    return this.maxCards;
  }

  public boolean isEmpty()
  {
    return this.numCards <= 0;
  }

  public boolean isFull()
  {
    return this.numCards > this.maxCards;
  }

  public void putCardIntoCardHolder(Card c) throws CardHolderException
  {
    if(this.isFull())
    {
      throw new CardHolderException("CardHolder is already full.");
    }
    else
    {
      this.theCards[this.numCards] = c;
      this.numCards++;
    }
  }

  public Card getCardFromCardHolder() throws CardHolderException
  {
    if(this.isEmpty())
    {
      throw new  CardHolderException("Attempt to remove card from empty CardHolder.");
    }
    Card retval = theCards.remove(0);
    return retval;
  }

  public String toString()
  {
    String retval = "";
    if(this.numCards <= 0)
    {
      retval = "Empty";
    }
    for (int i = 0; i < this.numCards; i++)
    {
      retval += this.theCards[i] + "\n";
    }
    return retval;
  }

  public static void main(String args[]) throws CardHolderException
  {
    CardHolder ch = new CardHolder();
    ch.putCardIntoCardHolder(new Card(1, 's'));
    ch.putCardIntoCardHolder(new Card(3, 'd'));
    ch.putCardIntoCardHolder(new Card(7,'c'));
    ch.putCardIntoCardHolder(new Card(13,'h'));

    System.out.println(ch);
  
    while(!ch.isEmpty())
    {
      System.out.println(ch.getCardFromCardHolder());
    }

    System.out.println(ch);
  }
}
