Class MarbleJar

java.lang.Object
   |
   +----MarbleJar

public class MarbleJar
extends Object
This class simulates a marble jar and the actions of Adding and Drawing marbles from the jar. The simulation supports two colors (white and black).
Adapted from the C++ class written by Dave Reed
18 Sept 1998
Modified Jan 1999

Author:
Craig Miller

Constructor Index

 o MarbleJar(int, int)
This constructs the marble jar initializing it with the number of colors specified by the parameters.

Method Index

 o addMarble(String)
This method simulates adding a new marble to the jar.
 o drawMarble()
This method simulates drawing one marble.
 o isEmpty()
This tests if the jar is empty.
 o main(String[])

Constructors

 o MarbleJar
 public MarbleJar(int black,
                  int white)
This constructs the marble jar initializing it with the number of colors specified by the parameters.

Parameters:
black - The number of black marbles.
white - The number of white marbles.

Methods

 o drawMarble
 public String drawMarble()
This method simulates drawing one marble. Precondition: the marble jar is not empty.

Returns:
The string specifying color of drawn marble ("white" or "black")
 o addMarble
 public void addMarble(String marble)
This method simulates adding a new marble to the jar.

Parameters:
marble - This string specifies the color of the marble added to the jar. It must be either "black" or "white".
 o isEmpty
 public boolean isEmpty()
This tests if the jar is empty.

Returns:
True if the jar is empty, false otherwise.
 o main
 public static void main(String args[])