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

/**********************************************************************
* This class represents a hand in the game of bridge.
*
* @author Jonathan Herman
* @version 1
**********************************************************************/
// Elizabeth Adams
// Date: 3/06/07
// PA 2
// Section: 2

public class BridgeHand
{
	private int nextCard;
	private String playerName;
	private Card[] hand;
	
	/**
	* Default constructor.
	*/
	public BridgeHand()
	{
		nextCard = 0;
		hand = new Card [13];
		this.playerName = "no name";
	}
	
	/**
	* This constructor creates a new BridgeHand with a given playerName and
	* gives it an array to hold 13 cards.
	*
	* @param playerName The name of the player the BridgeHand belongs to.
	*/	
	public BridgeHand (String playerName)
	{
		nextCard = 0;		
		hand = new Card [13];
		this.playerName = playerName;
	}
	
	/**
	* This method returns the numeric value corresponding to the BridgeHand.
	*
	* @return The value of the hand.
	*/	
	public int evaluateHand()
	{
		int score;		
		score = 0;
		
		// adds the point value of each card in hand to score	
		for (int x = 0; x < hand.length; x++)
			score += hand[x].getPoints();
			
		return score;
	}
	
	/**
	* This method puts a given card into the next available field in hand.
	*
	* @param aCard The card to be inserted.
	*/	
	public void putCardInHand (Card aCard)
	{
		hand [nextCard] = aCard;
		nextCard ++;
	}
	
	/**
	* This method returns the playerName.
	*
	* @return The playerName.
	*/	
	public String getName()
	{
		return playerName;
	}
	
	/**
	* This method returns true if two BridgeHands have the same score but 
	* belong to different players.
	*
	* @param other The 2nd BridgeHand to compare.
	* @return The result of the comparison.
	*/	
	public boolean equalScore (BridgeHand other)
	{
		if ((this.evaluateHand() == other.evaluateHand()) &&
			 (this.getName().compareTo (other.getName()) != 0))
			return true;
		else
			return false;
	}
	
	
	/**
	* This method returns a String with the owner, contents, and score of the
	* BridgeHand.
	*
	* @return The owner, contents, and score of the BridgeHand.
	*/	
	public String toString()
	{
		String myString;	
		
		// adds the player's name to myString
		myString = playerName + "'s hand: \n";
		
		// adds each field in hand to myString
		for (int x = 0; x < hand.length; x++)
			myString += hand [x] + "\n";
		
		// adds the hands value to myString
		myString += "This hand is worth " + evaluateHand() + " points.\n";
		
		return myString;
	}
		
} // end BridgeHand class