forked from ashishps1/awesome-low-level-design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dispense_state.py
27 lines (21 loc) · 1.1 KB
/
dispense_state.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from vending_machine_state import VendingMachineState
from product import Product
from coin import Coin
from note import Note
class DispenseState(VendingMachineState):
def __init__(self, vending_machine):
self.vending_machine = vending_machine
def select_product(self, product: Product):
print("Product already selected. Please collect the dispensed product.")
def insert_coin(self, coin: Coin):
print("Payment already made. Please collect the dispensed product.")
def insert_note(self, note: Note):
print("Payment already made. Please collect the dispensed product.")
def dispense_product(self):
self.vending_machine.set_state(self.vending_machine.ready_state)
product = self.vending_machine.selected_product
self.vending_machine.inventory.update_quantity(product, self.vending_machine.inventory.get_quantity(product) - 1)
print(f"Product dispensed: {product.name}")
self.vending_machine.set_state(self.vending_machine.return_change_state)
def return_change(self):
print("Please collect the dispensed product first.")