Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Write the class SodaMachine that will represent a typical soda vending machine (product name, price). An instance of SodaMachine has access to three methods,

Python

Write the class SodaMachine that will represent a typical soda vending machine (product name, price). An instance of SodaMachine has access to three methods, purchase, deposit and restock that will describe its interaction with the user returning strings. Tip: use the string format method

Here is the base code=====

class SodaMachine: ''' Creates instances of the class SodaMachine. Takes a string and an integer ''' def __init__(self, product, price): #-- start code here ---

#-- ends here ---

def purchase(self): #-- start code here ---

#-- ends here ---

def deposit(self, amount): #-- start code here ---

#-- ends here ---

def restock(self, amount): #-- start code here ---

#-- ends here ---

Here are some example out puts=====

>>> m = SodaMachine('Coke', 10)

>>> m.purchase() 'Product out of stock'

>>> m.restock(2) 'Current soda stock: 2'

>>> m.purchase() 'Please deposit $10'

>>> m.deposit(7) 'Balance: $7'

>>> m.purchase() 'Please deposit $3'

>>> m.deposit(5) 'Balance: $12'

>>> m.purchase()

'Coke dispensed, take your $2'

>>> m.deposit(10) 'Balance: $10'

>>> m.purchase() 'Coke dispensed'

>>> m.deposit(15)

'Sorry, out of stock. Take your $15 back'

>>> x = SodaMachine('Dr. Pepper', 8)

>>> x.restock(1) 'Current soda stock: 1'

>>> x.deposit(8) 'Balance: $8'

>>> x.purchase()

'Dr. Pepper dispensed'

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions

Question

8. Explain competency models and the process used to develop them.

Answered: 1 week ago