Class TossableFairCoin

java.lang.Object
  extended by TossableFairCoin

public class TossableFairCoin
extends java.lang.Object

An instance of this class models a coin that can be tossed to yield heads or tails, with equal probability.


Constructor Summary
TossableFairCoin()
          Initializes the coin's fields.
 
Method Summary
 boolean isHeads()
          Reports whether or not the coin is showing heads.
 boolean isTails()
          Reports whether or not the coin is showing tails.
 int numHeadsTossed()
          Reports the number of times during its lifetime that the coin has been tossed to yield heads.
 int numTailsTossed()
          Reports the number of times during its lifetime that the coin has been tossed to yield tails.
 int numTimesTossed()
          Reports the number of times during its lifetime that the coin has been tossed.
 void toss()
          Tosses the coin, after which there is a probability of 1/2 that the coin shows heads, and similarly for tails.
 java.lang.String toString()
          Returns a string indicating which side of the coin is showing, heads or tails.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TossableFairCoin

public TossableFairCoin()
Initializes the coin's fields.

Method Detail

isHeads

public boolean isHeads()
Reports whether or not the coin is showing heads.

Returns:
true if the coin is showing heads, false otherwise

isTails

public boolean isTails()
Reports whether or not the coin is showing tails.

Returns:
true if the coin is showing tails, false otherwise

numHeadsTossed

public int numHeadsTossed()
Reports the number of times during its lifetime that the coin has been tossed to yield heads.

Returns:
number of times the coin has been tossed to yield heads

numTailsTossed

public int numTailsTossed()
Reports the number of times during its lifetime that the coin has been tossed to yield tails.

Returns:
number of times the coin has been tossed to yield tails

numTimesTossed

public int numTimesTossed()
Reports the number of times during its lifetime that the coin has been tossed.

Returns:
number of times the coin has been tossed

toString

public java.lang.String toString()
Returns a string indicating which side of the coin is showing, heads or tails.

Overrides:
toString in class java.lang.Object
Returns:
a string indicating which side of the coin is showing

toss

public void toss()
Tosses the coin, after which there is a probability of 1/2 that the coin shows heads, and similarly for tails.