Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 h . Give back the customer change When the customer is done purchasing items, the machine should give back the remaining balance to the

1h. Give back the customer change
When the customer is done purchasing items, the machine
should give back the remaining balance to the customer.
Implement a method called output_change that checks if
there is any change to be given back and, if so, prints the
change in the following format:
It should then set the customer's balance to 0.0, indicating
the change has been given back to the customer.
If no change needs to be given back, it should simply
print the messaqe:
Testing recommendations for output_change:
When there is change (i.e., balance >0)
When there is no change (i.e., balance =0)
1i. Remove an item from the vending
machine
If a snack is not selling well, the owner may want to remove
it completely from the selection so it will no longer be
restocked. Implement a method called remove_item that
takes the name of a snack as a parameter, and removes it
from the vending machine. If successful, it should print the
following message:
{ITEM} removed from inventory
If the item to be removed does not exist in the machine, it
should print the following message:
Testing recommendations for remove_item:
Removing a valid item
Removing an invalid item 1e. Display the list of snacks and their
quantities
A vending machine should be able to display the list of
stacks, including their names, costs and quantities. Your
class should have a method called list_items that
prints the following string if there are no items in the
machine (i.e., an empty vending machine):
No items in the vending machine
Otherwise, it should print the list of snacks with their
respective quantities in the following format, sorted
alphabetically based on the item name.
Hint: Python's sorted() function can be used to sort
sequences and containers like lists and dictionaries. How to
use sorted() is dependent on how you chose to store your
vending machine items.
Here's an example of sorting a dictionary by key.
And here's an example of sorting a list of dictionaries by key
using a lambda function: 1c. Get the price of an item in the vending
machine
Before making a purchase, the customer may need to check
the price of an item. Your class should have a method called
get_item_price that takes an item's name as a parameter
and returns the price of that item. If the item does not exist
in the vending machine, it should print the following and
return None:
Testing recommendations for get_item_price:
Get price of a valid item
Get price of an invalid item
1d. Get the quantity of an item in the
vending machine
The owner may want to periodically check the quantity of a
snack to decide if it needs to be restocked. Your class
should have a method called get_item_quantity that
takes an item's name as a parameter, and returns the
quantity of that item. If the item does not exist in the vending
machine, it should print the following and return None:
Testing recommendations for get_item_quantity:
Get quantity of a valid item
Get quantity of an invalid item1a. Implement the constructor
Create a class named VendingMachine and a constructor
that creates and initializes attributes. Other than self, the
constructor should NOT take any additional parameters. As
mentioned in the Important Notes section, it's up to you to
decide what variables to create in the constructor. If you
followed the suggestion in the Important Notes section, you
should already have an idea. You can always come back to
the constructor to modify and/or add attributes as needed.
1b. Add items to the vending machine
Periodically, we may want to restock the current snacks in
the vending machine, or add brand new snacks. Your class
should have the method add_item that takes an item's
name, price and quantity as parameters (don't forget
self too ... this will be your last reminder about self). The
method should add the item to the vending machine. Note
that if the item already exists, the method should update the
price and add the quantity to the existing stock. (At this
point, you should think deeply about how you want to hold
several pieces of information about every item currently in
the vending machine. Setting up an organized way to store
and handle this data now will help you tremendously going
forwards.) When successfully added, the method should
print the quantity and the item name in the following format:
{QUANTITY}{ITEM_NAME}(s) added to inventory
Here, QUANTITY } and {ITEM_NAME } are the actual quantity
and name of the item, respectively. Going forwards, we will
always use VARIABLE
image text in transcribed

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

Step: 3

blur-text-image

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

Knowledge Discovery In Databases

Authors: Gregory Piatetsky-Shapiro, William Frawley

1st Edition

0262660709, 978-0262660709

More Books

Students also viewed these Databases questions