import java.util.Random;

class Deck extends CardHolder
{
  private final int NUMSHUF = 10000;
  private Random ran = null;

  public Deck(boolean initialize)
  {
    super(52);
    ran = new Random();

    if(initialize)
    {
      int where = 0;
      for(int i = 1; i <= 13; i++)
      {
        this.theCards[where] = new Card(i, 'C');
        where++;
      } 
      for(int i = 1; i <= 13; i++)
      {
        this.theCards[where] = new Card(i, 'D');
        where++;
      } 
      for(int i = 1; i <= 13; i++)
      {
        this.theCards[where] = new Card(i, 'H');
        where++;
      } 
      for(int i = 1; i <= 13; i++)
      {
        this.theCards[where] = new Card(i, 'S');
        where++;
      } 
    }
    this.numCards = 52;
  }

  public void shuffle()
  {
    Card temp;
    int where;
    for(int i = 0; i < NUMSHUF; i++)
    {
      where = ran.nextInt(52);
      temp = this.theCards[where];
      this.theCards[where] = this.theCards[0];
      this.theCards[0] = temp;
    }
  }

  public void deal(int numInHand, CardHolder ...hands) throws CardHolderException
  {
    for(int i = 0; i < numInHand; i++)
    {
      for(int j = 0; j < hands.length; j++)
      {
        if(this.numCards > 0)
        {
          hands[j].putCardIntoCardHolder(this.getCardFromCardHolder());
        }
      }
    }
  }
        

  public static void main(String args[]) throws CardHolderException
  {
    CardHolder hand1 = new CardHolder();
    CardHolder hand2 = new CardHolder();
    Deck myDeck = new Deck(true);
    System.out.println(myDeck);
    System.out.println();
    myDeck.shuffle();
    myDeck.deal(26, hand1, hand2);
    System.out.println(myDeck);

    System.out.println(hand1);
    System.out.println();
    System.out.println(hand2);

  }
}
