Class Coin

java.lang.Object
  |
  +--Coin

public class Coin
extends Object

A Coin has an orientation, either heads or tails, and a value.

Author:
Suzanne Menzel, menzel@cs.indiana.edu

Constructor Summary
Coin()
          A default Coin is created with a random orientation and a value of one.
Coin(int value)
          Creates a Coin with the given value and a random orientation.
 
Method Summary
 boolean equals(Coin c)
          Two Coins are equals to one another if they have the same value and the same orientation.
 Coin flip()
          This Coin is flipped in the air and returned.
 int getValue()
          Returns the value of this Coin.
 boolean isHeads()
          This predicate returns true if the coin is oriented heads up, and false otherwise.
 boolean isTails()
          This predicate returns true if the coin is oriented tails up, and false otherwise.
 String toString()
          Returns a String representation of the coin's state.
 Coin turnOver()
          Inverts the orientation of this Coin.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Coin

public Coin()
A default Coin is created with a random orientation and a value of one.


Coin

public Coin(int value)
Creates a Coin with the given value and a random orientation.

Method Detail

flip

public Coin flip()
This Coin is flipped in the air and returned.


getValue

public int getValue()
Returns the value of this Coin.


turnOver

public Coin turnOver()
Inverts the orientation of this Coin. If it was heads before, it's tails afterward. If is was tails before, it's heads afterward.


isHeads

public boolean isHeads()
This predicate returns true if the coin is oriented heads up, and false otherwise.


isTails

public boolean isTails()
This predicate returns true if the coin is oriented tails up, and false otherwise.


equals

public boolean equals(Coin c)
Two Coins are equals to one another if they have the same value and the same orientation.


toString

public String toString()
Returns a String representation of the coin's state.

Overrides:
toString in class Object