import java.io.*;
import java.util.*;

/**********************************************************************
* This class represents a deck of 52 cards.
*
* @author Jonathan Herman
* @version 1
**********************************************************************/
// Elizabeth Adams
// Date: 3/06/07
// PA 2
// Section: 2

public class Deck
{
	private static int dealt;
	private static Card[] cards;
	
	/**
	* This constructor creates a Deck with 52 cards.
	*/
	public Deck()
	{
		int counter;
		
		counter = 0;
		dealt   = -1;		
		cards = new Card [52];
		
		// fills the array with Cards for each possible suit and rank
		for (Suit s: Suit.values())
			for (Rank r: Rank.values())
			{
				cards [counter] = new Card (r, s);
				counter ++;
			}
	}
	
	/**
	* This method shuffles the Deck by swapping two random Cards fifty times.
	*/
	public void shuffle()
	{
		int index1, index2;
		
		Random rand;
		Card tempCard;
		
		rand = new Random();
		
		// swaps two random cards in the deck
		for (int x = 0; x < 50; x++)
		{
			// generates two random indices
			index1 = rand.nextInt (52);
			index2 = rand.nextInt (52);
			
			// swaps the cards at those two indices
			tempCard = cards [index1];
			cards [index1] = cards [index2];
			cards [index2] = tempCard;
		}		
	}
	
	/**
	* This method increments the index of the next available card and returns
	* the card at that index.
	*
	* @return The next available Card.
	*/
	public Card deal()
	{
		dealt ++;				
		return cards [dealt];
	}
	
	/**
	* This method returns the contents of the Deck.
	*
	* @return The contents of the Deck.
	*/
	public String toString()
	{
		String deck;
		deck = "";
		
		// adds each card to deck
		for (int x = 0; x < cards.length; x++)
			deck += cards[x] + "\n";
			
		return deck;
	}
	
} // end Deck class