public class CardHolder
{
  Card theCards[];
  int numCards;

  public CardHolder(boolean fill)
  {
    this.theCards = new Card[52];
    this.numCards = 0;
    char suit;
    if(fill)
    {
      int where = 0;
      for(int s = 0; s < 4; s++)
      {
        if(s == 0)
          suit = 'C';
        else if (s == 1)
          suit = 'D';
        else if (s == 2)
          suit = 'H';
        else
          suit = 'S'; 
        for(int val = 1; val <= 13; val++)
        {
          theCards[this.numCards] = new Card(val, suit);
          this.numCards++;
        }
      }
    }
  }

  public CardHolder()
  {
    this(false);
  }  

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

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

  public boolean isFull()
  {
    return numCards == theCards.length;
  }

  public Card getCardFromHolder()
  {
    if(this.isEmpty())
      throw new CardHolderException("Attempt to get card from empty container");
    Card retval = this.theCards[0];
    this.numCards--;
    for(int i = 0; i < numCards; i++)
    {
      this.theCards[i] = this.theCards[i+1];
    }
    return retval;
  }

  public void putCardIntoHolder(Card c)
  {
    if(this.isFull())
      throw new CardHolderException("Attempt to overfill card holder");
    this.theCards[this.numCards] = c;
    this.numCards++; 
  }

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

  public static void main(String args[])
  {
    CardHolder deck = new CardHolder(true);
    System.out.print(deck);

    Card c1 = deck.getCardFromHolder();
    deck.putCardIntoHolder(c1);
    System.out.print(deck);
  }
}
 
