Question: Section 3 : The Vendor and VendingMachine classes ( 4 pts ) These classes will represent a vendor ( someone that makes goods and services
Section : The Vendor and VendingMachine classes pts
These classes will represent a vendor someone that makes goods and services available to
companies or consumers and a vending machine that gives the user money back only when a
transaction is cancelled, after making a purchase change back or if the machine is out of all
stock.
Instances of VendingMachine are created through an instance of the Vendor class already
implemented for you in the starter code using the install method. This vending machine will sell
four different products:
Product ID Price
When creating an instance of VendingMachine, the machine starts out with items of each
product. A VendingMachine object returns strings describing its interactions. All numbers
representing money must be displayed as floats.
VendingMachine
Your attributes here
purchaseitem: int, qty: int str
depositamount: intfloat str
restockitem: int, stock: int str
isStocked bool
getStock dict
cancelTransaction None, str
Class diagram for VendingMachine
Note: Read the description of all methods first, then outline your strategy. In this section, you are
expected to reduce the amount of repeated code by calling methods in the class to reuse code. Both
functionality and design are part of the grade.
purchaseself item, qty
Attempts to buy something from the vending machine. Before completing the purchase, check to
make sure the item is valid, there is enough stock of said item, and there is enough balance.
Output in order of priority
str
Invalid item if the item id is invalid Highest priority
Machine out of stock is returned if the machine is out of stock for all items
Item out of stock is returned if there is no stock left of requested item.
Current itemid stock: stock, try again if there is not enough stock
Please deposit $remaining if there is not enough balance
Item dispensed if there is no money to give back to the user
Item dispensed, take your $change back if there is change to give back
depositself amount
Deposits money into the vending machine, adding it to the current balance.
Output
str Balance: $balance when machine is stocked
Machine out of stock. Take your $amount back if the machine is out of stock.
restockself item, stock
A protected method that adds stock to the vending machine. Note that when the VendingMachine
runs out of a product, a Vendor object will trigger the operation using its restock method already
implemented for you
Output
str Current item stock: stock for existing id
Invalid item is returned if the item id is invalid.
isStockedself
A property method behaves like an attribute that returns True if any item has any nonzero stock,
and False if all items have no stock.
Output
bool Status of the vending machine.
getStockself
A property method behaves like an attribute that gets the current stock status of the machine.
Returns a dictionary where the key is the item and the value is the list price stock
Output
dict Current stock status represented as a dictionary.
cancelTransactionself
Returns the current balance to the user
Output
None Nothing is returned if balance is
str Take your $amount back if there is money to give back
Examples:
vendor VendorJohn Doe'
x vendorinstall
xgetStock
: : : :
xpurchase
'Invalid item'
xpurchase
'Please deposit $
xdeposit
'Balance: $
xpurchase
'Item dispensed, take your $ back'
xisStocked
True
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
