Angad Sandhu
Search
Browse

idle_state

Source name
idle_state.py
# ================================================================
# File: vendingmachine/idle_state.py
# Description:
#   Implements the IdleState behavior.
#   - In IdleState, no product is selected yet.
#   - Prompts user to select a product.
#
# Steps Covered:
# 4. Determine Core Methods Based on Use Cases.
# 7. Exception Handling and Edge Cases.
# ================================================================

from vending_machine_state import VendingMachineState
from product import Product
from coin import Coin
from note import Note

class IdleState(VendingMachineState):
    def __init__(self, vending_machine):
        self.vending_machine = vending_machine

    def select_product(self, product: Product):
        if self.vending_machine.inventory.is_available(product):
            self.vending_machine.selected_product = product
            self.vending_machine.set_state(self.vending_machine.ready_state)
            print(f"Product selected: {product.name}")
        else:
            print(f"Product not available: {product.name}")

    def insert_coin(self, coin: Coin):
        print("Please select a product first.")

    def insert_note(self, note: Note):
        print("Please select a product first.")

    def dispense_product(self):
        print("Please select a product and make payment.")

    def return_change(self):
        print("No change to return.")

Browse the library