Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part B In this program you will be writing a class to simulate a gumball machine that you might see at a store, Your class

image text in transcribedimage text in transcribed

Part B In this program you will be writing a class to simulate a gumball machine that you might see at a store, Your class should work as follows: Constructor - The constructor (_init_ 0 method) should accept a capacity for the gumball machine (how many gumballs it's filled with) as an integer. The gumball machine should store this capacity as an instance variable. No data validation is required. - The constructor should also store an instance variable to keep track of how much money is in the machine. All machines are constructed to be empty and have no money in them. - The constructor should also create a new instance variable (a list) to hold that many gumballs. Fill this list with a random set of gumballs - each gumball can be either red, green or blue. For example, if you create a gumball machine with a capacity of 4 the machine could create a list that looks like the following: [' red', 'green', 'green', 'blue']. - The constructor should announce that it was constructed with the desired capacity. Methods - report 0 : This method should accept no arguments and simply report out the current status of the gumball machine. For example: Gunbal1 Vachine Report: - Guaballs in machine: 5 - Voney in machine: \$0,00 dispense 0: This method should accept an argument-a coin value-and determine if that coin value is a quarter (i.e. 0.25 ). If so, a gumball should be removed from the list and reported to the user. The machine should also accept the coin and increase its internal count of how much money is in the machine. Note that if the gumball machine is empty a new gumball will not be dispensed, and the coin should be rejected. - count_gubbal1s_by_type 0: This method should accept a single argument-a string representing the type of gumballand print out how many types of that gumball are left in the machine. Here is some sample code you can run to test your program, along with a possible set of output (which will be different since your gumball machine will contain a random assortment of gumballs). = EXPECTED OUTPUT Gumball Nachine created with 5 randon sumballs Gumball Nachine Report: - Gubba11s in nachine: 5 - Noner in nachine: $0.00 There are 1 gunballs of type red in the machine There are 1 gunballs of type green in the nachine There are 3 gunballs of type blue in the nachine Invalid coin, no gunball vill be dispensed Invalid coin, no gunball vill be dispensed Invalid coin, no gunball vill be dispensed Gunba11 Machine Report: - Gumballs in nachine: 5 - Voney in nachine: $0.00 There are 1 gunballs of type red in the machine There are 1 gunballs of type green in the nachine There are 3 gunballs of type blue in the nachine Accepting 0.25; Dispensing a red gunball Accepting 0.25: Dispensing a blue gunball Accepting 0.25; Dispensing a blue gunball Gunba11 Machine Report: - Gunballs in nachine: 2 - Voney in nachine: $0.75

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions

Question

For a given aqueous solution, if [OH] = 3.77 104 M, what is [H+]?

Answered: 1 week ago