|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--Coin
Histogram Project:
*
* Coin objects simulate a coin that, when tossed, has an equal
* probability of turning up heads or tails. When the coin is first
* constructed, both the heads and tails methods
* will return false. Once the toss method has been
* called for the first time, however, either heads or
* tails (but not both) will always be true. Between
* calls to the toss method, the heads and
* tails methods can be called as often as desired and will
* always return the same true/false value
* (in other words, the only way to change whether the coin is showing heads
* or tails is to toss the coin).
*
*
* By default, a Coin object will produce a different series
* of numbers (through repeated calls to the toss method) every
* time the program is run. When testing, though, it is often useful to have
* a program generate the same sequence of numbers each time it is run; this
* can be achieved by specifying a "seed" before constructing coins.
*
* @author Pamela Cutter
* @version Jan 4, 2003
| Constructor Summary | |
Coin()
Constructs a coin that has not yet been tossed; neither * heads nor tails will return
* true until the toss method is
* invoked. |
|
| Method Summary | |
boolean |
heads()
Reports whether the last coin toss came up heads. |
static void |
setSeed(long seed)
Seeds the random number generator used by coins. |
boolean |
tails()
Reports whether the last coin toss came up tails. |
void |
toss()
Tosses this coin. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Coin()
heads nor tails will return
* true until the toss method is
* invoked. The coin is balanced, so each coin toss has
* an equal (0.5) probability of turning up heads or tails.
| Method Detail |
public static void setSeed(long seed)
static keyword indicates that this method
* does not have to be invoked on a specific Coin
* object; instead, it can be invoked on the class, as in
* Coin.setSeed(longValue).
public void toss()
public boolean heads()
true if the last coin toss
* resulted in a coin showing heads;
* false otherwise.
public boolean tails()
true if the last coin toss
* resulted in a coin showing tails;
* false otherwise.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||