cardgame
Class Player

java.lang.Object
  |
  +--cardgame.Player

public class Player
extends java.lang.Object

The Player class models an individual card player. A Player has a name and holds a hand of cards.

Version:
1.0, 4 August 2001
Author:
James A. Webb, www.uberkode.com

Field Summary
private  java.util.Vector hand
          The private variable hand is a Java Vector that stores the PlayingCards that a Player is holding.
private  int money
          The private variable money stores the amount of money a Player has at a given time.
private  java.lang.String name
          The private variable name stores the name assigned to a Player.
 
Constructor Summary
Player()
          The no-argument constructor creates a Player with the name "Unknown" and an zero initial amount of money.
Player(java.lang.String playerName, int initialMoney)
          This constructor creates a Player with a specified name and initial amount of money.
 
Method Summary
 boolean equals(Player theOtherPlayer)
          The public method equals checks whether two Players are the same by testing whether the names are the same, returning a boolean result.
 int getMoney()
          The public method getMoney retrieves the amount of money a Player currently has.
 java.lang.String getName()
          The public method getName retrieves the name a Player is using for a game.
 java.lang.String getPlayerState()
          The public method getPlayerState returns a useful String representation of the current state of a Player.
 void setMoney(int moneyAmount)
          The public method setMoney specifies the amount of money a Player wins or loses.
 void setName(java.lang.String playerName)
          The public method setName specifies the name a Player will use.
 java.lang.String toString()
          The public method toString returns a complete specification of a Player's current state in a convenient tagged format.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

name

private java.lang.String name
The private variable name stores the name assigned to a Player. Player names must be unique for a given game.
See Also:
getName(), setName(String playerName)

money

private int money
The private variable money stores the amount of money a Player has at a given time. The amount is stored as an integer, and thus represents whole numbers of dollars, euros, credits, or chips.
See Also:
getMoney(), setMoney(int moneyAmount)

hand

private java.util.Vector hand
The private variable hand is a Java Vector that stores the PlayingCards that a Player is holding.
See Also:
PlayingCard
Constructor Detail

Player

public Player()
The no-argument constructor creates a Player with the name "Unknown" and an zero initial amount of money.
See Also:
name, money

Player

public Player(java.lang.String playerName,
              int initialMoney)
This constructor creates a Player with a specified name and initial amount of money.
Parameters:
playerName - the name a Player will use for a game.
initialMoney - the initial amount of money a Player is given.
See Also:
name, getName(), setName(String playerName), money, getMoney(), setMoney(int moneyAmount)
Method Detail

getName

public java.lang.String getName()
The public method getName retrieves the name a Player is using for a game.
Returns:
the name of a Player as a String.
See Also:
name, setName(String playerName)

setName

public void setName(java.lang.String playerName)
The public method setName specifies the name a Player will use.
Parameters:
playerName - the name a Player will use for a game.
See Also:
name, getName()

getMoney

public int getMoney()
The public method getMoney retrieves the amount of money a Player currently has.
Returns:
the amount of money a Player has as an int.
See Also:
money, setMoney(int moneyAmount)

setMoney

public void setMoney(int moneyAmount)
The public method setMoney specifies the amount of money a Player wins or loses. Money is added to a Player's holdings by specifying a positive amount, and money is subtracted by specifying a negative amount.
Parameters:
moneyAmount - the amount of money given to a Player.
See Also:
money, getMoney()

getPlayerState

public java.lang.String getPlayerState()
The public method getPlayerState returns a useful String representation of the current state of a Player.
Returns:
the state of a Deck as a String.

toString

public java.lang.String toString()
The public method toString returns a complete specification of a Player's current state in a convenient tagged format.
Overrides:
toString in class java.lang.Object
Returns:
the state of a Player as a formatted String.
See Also:
name, money

equals

public boolean equals(Player theOtherPlayer)
The public method equals checks whether two Players are the same by testing whether the names are the same, returning a boolean result.
Parameters:
theOtherPlayer - the Player to be compared with this Player.
Returns:
the boolean result of the comparison.
See Also:
name