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
-
MarbleJar(int, int)
- This constructs the marble jar initializing it with the number of
colors specified by the parameters.
-
addMarble(String)
- This method simulates adding a new marble to the jar.
-
drawMarble()
- This method simulates drawing one marble.
-
isEmpty()
- This tests if the jar is empty.
-
main(String[])
-
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 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(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(String args[])