
/****************************
*This program makes the deck,
*shuffles the cards, and deals
*them to the four players
*@author - Bryan Wiseman
*@version - 1
*****************************/
//Date: 3/13/07
//Section: 1
//PA:2

    public class Deck
   {
      Card[] deck;
      int num;
   	 
   	//constructor of the deck
       public Deck()
      {
         deck = new Card [52];
         num = -1;
      		
         int index;
      
         index = 0;
      
      
         for(Suit x : Suit.values())
            for(Rank y :Rank.values())
            {
               deck[index] = new Card( y, x);
               index++;
            }
      	
      }
   
   
   	/*******************
		*Method shuffles the 
		*Deck into a random order
		********************/
       public void shuffle()
      {
         int ranHolder1;	//first random position in deck
         int ranHolder2;	//second random position in deck
         Card holder; 		//holds card value for the switch
      
         ranHolder1 = 0;
         ranHolder2 = 0;
      	//loop shuffles the deck
         for(int num = 0; num <= 75; num++)
         {
            ranHolder1 =  (int) (Math.random() * 51 + 1);
            ranHolder2 =  (int) (Math.random() * 51 + 1);
         
            if(ranHolder1 == ranHolder2)
            {
               ranHolder2 =  (int) (Math.random() * 51 + 1);
            }
         
            holder = deck[ranHolder1];
            deck[ranHolder1] = deck[ranHolder2];
            deck[ranHolder2] = holder;
         }
      }
   	/******************
		*Method deals out the 
		*cards in the deck to
		*the hand
		*@return - Card 
		********************/
       public Card deal()
      {
      
         num += 1;
      
      
         return deck[num];
      
      
      }
   	/********************
		*Method puts the deck
		*into string format
		*@return - deck in String format
		***********************/
       public String toString()
      {
         String output;	//output string
      
         output = "";
      
         for(int num = 0; num < deck.length; num++)
         {
            output = output + deck[num].toString() + "\n";
         } 
      
         return output;
      }
   
   
   
   
   }