7from abc
import ABC, abstractmethod
8from typing
import TypeAlias
10Visitor_Village : TypeAlias =
"Visitor_Village"
12from .visitor_ordervisitor
import OrderVisitor
13from .visitor_class
import Visitor
29 if len(left) == len(right):
31 for left_item
in left:
32 if left_item
not in right:
58 def Name(self, name : str) ->
None:
86 def Village(self, v : Visitor_Village) ->
None:
103 @IngredientsForItems.setter
174 return ", ".join(items)
196 outOfStockItems.append(item)
197 itemsInThisShop.append(item)
200 print(
" {0}: Received an order for {1}.".format(
205 for itemToOrder
in outOfStockItems:
207 print(
" {0}: {1} out of stock, ordering ingredients to make more...".format(
218 print(
" {0}: {1} out of stock, making...".format(
233 def PickupOrder(self, items : list[str], itemsToBePickedUp : list[str]) ->
None:
238 itemsToBePickedUp.append(item)
240 print(
" Error! {0}: Item {1} is not in the inventory when it should be.".format(
243 if itemsToBePickedUp:
244 itemsReceivedFromThisShop = []
246 for itemToBePickedUp
in itemsToBePickedUp:
249 itemsReceivedFromThisShop.append(itemToBePickedUp)
251 print(
" {0}: Order picked up for {1}.".format(self.
NameName, output))
261 def Accept(self, visitor : Visitor) ->
None:
A visitor used for ordering items from various shops.
Base class that all shops must implement.
None PickupOrder(self, list[str] items, list[str] itemsToBePickedUp)
Pick up the items sold by this shop (assumes the items were ordered already).
str Address(self)
Property getter for the address of the shop: value = o.Address.
None Accept(self, Visitor visitor)
The visitor will call this method on each element it wants to visit.
_ingredientsForItems
Map of ingredients required for inventory items.
bool PlaceOrder(self, list[str] items)
Place an order for the specified items.
_shopAddress
address of this shop
_inventory
Inventory for this shop, keyed by ingredient name and holding the the count of each ingredient.
dict[str, int] Inventory(self)
Property getter for the inventory maintained by the shop: value = o.Inventory
_village
The Visitor_Village object this shop is in.
bool IsItemInStock(self, str item)
Determine if this shop has the specified item in stock.
_shopName
Name of this shop.
bool DoesShopSellItem(self, str item)
Determine if this shop sells the specified item.
None AddItemToInventory(self, str item)
Add the specified item to this shop's inventory.
str Name(self)
Property getter for the name of the shop: value = o.Name
None Name(self, str name)
Property setter for the name of the shop: o.Name = value
None __init__(self)
Default Constructor.
dict[str, list[str]] IngredientsForItems(self)
Property getter for the ingredients needed for each item sold by the shop: value = o....
str StringizeList(self, list[str] items)
Convert a string list to a comma-delimited string.
def are_list_contents_the_same(list left, list right)
Determine if the two string lists have the same contents.
Represents a collection of shops that can be visited.