Modifying a Class

class MarbleJar
{
public:
   MarbleJar(int black, int white);  // initializes jar contents
   String DrawMarble ( );          // draws and returns color
   void AddMarble (String color);  // adds marble to jar
   Boolean IsEmpty ( );                 // returns true if empty
private:
   int myNumberBlack, myNumberWhite; // marbles in the jar
   int myRandom ( );                 // random number generator
};
Problem
Suppose the jar has also 100 red marbles. Draw three at a time. In 100 trials how many times are the three marbles the same color? What percent of the time?

Analysis
In this problem you will have to modify the class marbles.java. Copy this file to your directory and rename it mymarbl.java. Write an additional construct to accept three parameters. Will you have to modify any functions? If you do, be sure that your Lab A still works correctly when you call mymarbl.java instead of marbles.java. Now, modify your client LabA, renaming it as lab C, to draw three marbles at a time, compare, and tabulate results.


Continue to:  Unit 5 / Prev / Next