Files
at1/src/Cart.py
2026-03-16 10:19:16 +11:00

65 lines
1.8 KiB
Python

from typing import final
from PySide6.QtWidgets import QWidget
from Movie import Movie
from enum import Enum
class ShopItemType(Enum):
"""
Enum dictating types of items that can be bought from the cinema.
"""
Movie = 0
Popcorn = 1
Frozen_Coke = 2
@final
class ShopItem:
"""
Represents an item that can be bought from the cinema.
"""
def __init__(self, shoptype: ShopItemType, quantity: int, movie: Movie | None = None):
"""
Creates a new ShopItem.
Throws:
ValueError - type is ShopItemType.Movie, but movie is not provided as a paramater
Example (creates a ShopItem with type popcorn and quantity 3):
ShopItem(ShopItemType.Popcorn, 3)
"""
self.type = shoptype
self.movie = movie
self.quantity = quantity
self.cost: float
match shoptype:
case ShopItemType.Movie:
if movie is not None:
self.cost = movie.price
else:
raise ValueError("ShopItem with type ShopItemType.Movie must provide a movie as an argument")
case ShopItemType.Popcorn:
self.cost = 9.95
pass
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
class CartView(QWidget):
def __init__(self):
super().__init__()
global cart
self.setWindowTitle("Work in progress!")