Adding stuff to cart
This commit is contained in:
17
src/Cart.py
17
src/Cart.py
@@ -17,7 +17,7 @@ class ShopItem:
|
||||
"""
|
||||
Represents an item that can be bought from the cinema.
|
||||
"""
|
||||
def __init__(self, type: ShopItemType, quantity: int, movie: Movie | None = None):
|
||||
def __init__(self, shoptype: ShopItemType, quantity: int, movie: Movie | None = None):
|
||||
"""
|
||||
Creates a new ShopItem.
|
||||
Throws:
|
||||
@@ -25,13 +25,13 @@ class ShopItem:
|
||||
Example (creates a ShopItem with type popcorn and quantity 3):
|
||||
ShopItem(ShopItemType.Popcorn, 3)
|
||||
"""
|
||||
self.type = type
|
||||
self.type = shoptype
|
||||
self.movie = movie
|
||||
self.quantity = quantity
|
||||
self.cost: float
|
||||
match type:
|
||||
match shoptype:
|
||||
case ShopItemType.Movie:
|
||||
if movie != None:
|
||||
if movie is not None:
|
||||
self.cost = movie.price
|
||||
else:
|
||||
raise ValueError("ShopItem with type ShopItemType.Movie must provide a movie as an argument")
|
||||
@@ -41,18 +41,21 @@ class ShopItem:
|
||||
case ShopItemType.Frozen_Coke:
|
||||
self.cost = 4.95
|
||||
|
||||
def __repr__(self):
|
||||
return f"ShopItem(type={self.type}, movie={self.movie}, quantity={self.quantity}, cost={self.cost})"
|
||||
|
||||
@final
|
||||
class Cart:
|
||||
def __init__(self):
|
||||
self.contents: list[ShopItem] = []
|
||||
|
||||
def __repr__(self):
|
||||
return f"Cart(contents={self.contents})"
|
||||
|
||||
def addItem(self, item: ShopItem):
|
||||
self.contents.append(item)
|
||||
pass
|
||||
|
||||
cart = Cart()
|
||||
|
||||
|
||||
class CartView(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
Reference in New Issue
Block a user