Class MarbleJar
java.lang.Object
|
+--MarbleJar
- public class MarbleJar
- extends java.lang.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
Constructor Summary |
MarbleJar(int black,
int white)
This constructs the marble jar initializing it with the number of
colors specified by the parameters. |
Method Summary |
void |
addMarble(java.lang.String marble)
This method simulates adding a new marble to the jar. |
java.lang.String |
drawMarble()
This method simulates drawing one marble. |
boolean |
isEmpty()
This tests if the jar is empty. |
static void |
main(java.lang.String[] args)
|
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
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.
drawMarble
public java.lang.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")
addMarble
public void addMarble(java.lang.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".
isEmpty
public boolean isEmpty()
- This tests if the jar is empty.
- Returns:
- True if the jar is empty, false otherwise.
main
public static void main(java.lang.String[] args)