Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a class Starburst that represents a pack of Starburst pieces. Each Starburst object, will keep track of one data attribute, a list of the
Write a class Starburst that represents a pack of Starburst pieces. Each Starburst object, will
keep track of one data attribute, a list of the pieces of candy contained in the pack. For the sake of brevity, each
piece of candy will be represented by a single uppercase letter, representing its color. No data validation is
required Your class definition should include methods init eat WRITE YOUR
SOLUTION ON THE BACK OF THIS PAGE. Implementation details follow.
Creating and displaying objects:
constructor accepts one optional argument, a list of strings representing the colors of the pieces
of candy. If no argument is given, these pieces should default to RYBOGP
No data validation is required
returns a string representing the Starburst object indicated the examples below.
Starburst# list colors passed argument
Starburst
Starburst# argument, use default
Starburst
The eat method allows you to consume one or more pieces from the Starburst pack. Details:
accepts one optional argument, the number of pieces to eat. If no argument is provided, this defaults to
piece.
Tries to eat the given number of pieces from the front of the pack, however,
You can't eat pieces that aren't there the actual number of pieces eaten is limited to the number of pieces
currently in the pack
Pieces that are eaten are removed from the front of the pack
returns a list of the pieces actually eaten. If none are eaten, an empty list is returned.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started