Question: This program will simulate pulling one marble out of a bag with six marbles. The marbles will be one of: Blue Red Green Purple White

This program will simulate pulling one marble out of a bag with six marbles. The marbles will be one of:
Blue
Red
Green
Purple
White
Black
One the marbles color is noted, it is put back in the bag. So, for example, the following are perfectly valid results of pulling three marbles of the bag:
Blue, Red, White
Blue, Blue, Black
Red, Purple, Red
Write a class named MarbleBag. The MarbleBag class should have the following field:
A private String named marble. The marble field will be one of the six colors listed above.
The Coin class should have the following methods:
A no-arg constructor that randomly pulls a marble out of the bag.
A void method named pull() that simulates pulling a marble out of the bag. When the pull() method is called, it randomly determines the marble color that was pulled.
A method named getMarble() that returns the value of the marble field.
Write a program that demonstrates the MarbleBag class. The program should:
Create an instance of the class
Display the marble that is initially drawn
Use a loop to draw 20 marbles
Each time a marble is drawn:
Display the marble color
Keep count of the number of times each color appears
After the loop, display the total number of each color that appeared

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!