Question: Java programming Create a class MarblesJar that has the following members: - An enum of colors (as many colors as you want) called ColorValues and
Java programming
Create a class MarblesJar that has the following members:
- An enum of colors (as many colors as you want) called ColorValues and a particular color called 'color' that is of type ColorValues
- A static method that prints out the list of ColorValues called DisplayPossibleColors()
- An array of integers called marbleCounts. It has the same length as the number of items in ColorValues, and each element represents a total. For example marbleCounts[0] represents the number of marbles of color 0 (the enum value with ordinal 0 or in other words the first color ColorValues)
- A constructor that takes no arguments that fills the marble jar with 100 marbles
- A constructor that takes an integer as a number of marbles to fill the jar with
- A private int field 'numMarbles' with the number of marbles and an accessor/mutator for it
- A toString method that displays the color and count of marbles of each color in the marble jar along with the total numMarbles. For example it may look like:
BLUE: 10 RED: 15 GREEN: 5 TOTAL: 30
- In your main method, create a MarblesJar with the default and the overloaded constructor, and call toString() on each by printing them out via System.out.println(objRef) where objRef is the MarblesJar reference.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
