import java.util.*;

/**
 * An encapsulation of a Table for a card game (that contains
 * a Dealer object and one or more Player objects)
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class Table
{
    private Dealer                     dealer;
    private Hashtable                  players;


    /**
     * Default Constructor
     *
     * Constructs an "empty" table (i.e., with no Dealer object
     * and no Player objects)
     */
    public Table()
    {
	players = new Hashtable();
    }



    /**
     * Add a Player to this Table
     *
     * @param player    The Player to add
     */
    public void addPlayer(Player player)
    {
	players.put(player, player);
	player.playAtTable(this);
    }


    /**
     * Get the Dealer that is working at this Table
     *
     * @return   The Dealer
     */
    public Dealer getDealer()
    {
	return dealer;
    }


    /**
     * Get all of the Player objects that are 
     * playing at this Table
     *
     * @return   The Player objects
     */
    public Player[] getPlayers()
    {
	Player[]               current;
	Enumeration            e;
	int                    i, n;

	n = players.size();
	current = new Player[n];

	e = players.elements();
	i = 0;
	while (e.hasMoreElements())
	{
	    current[i] = (Player)(e.nextElement());
	    i++;
	}

	return current;
    }


    /**
     * Remove a Player from this Table
     *
     * @param player    The Player to remove
     */
    public void removePlayer(Player player)
    {
	players.remove(player);
    }



    /**
     * Assign a Dealer to work this Table
     *
     * @param dealer   The Dealer
     */
    public void setDealer(Dealer dealer)
    {
	this.dealer = dealer;
	dealer.playAtTable(this);
    }
}
