mail@pastecode.io avatar
a year ago
2.7 kB
class Movie:
    def __init__(self, name, price, stock, release_date, age_limit):
        self.name = name
        self.price = price
        self.stock = stock
        self.release_date = release_date
        self.age_limit = age_limit

    def rent_movie(self, num):
        if num > 0 and num <= self.stock:
            self.stock -= num
            return True
        return False

    def return_movie(self, num):
        if num > 0:
            self.stock += num
            return True
        return False

class Customer:
    def __init__(self, name, age, balance, rental_limit):
        self.name = name
        self.age = age
        self.balance = balance
        self.rental_limit = rental_limit
        self.rented_movies = []

    def can_rent_movie(self, movie):
        if self.age >= movie.age_limit and self.rental_limit > 0 and self.balance >= movie.price:
            return True
        return False

class MovieStore:
    def __init__(self):
        self.movies = []
        self.customers = []
        self.income = 0

    def add_movie(self, movie):
        # Check if movie already exists in the store
        for m in self.movies:
            if m.name == movie.name:
                # If movie exists, just update the stock
                m.stock += movie.stock
        # If movie doesn't exist, add it to the list

    def remove_movie(self, movie_name):
        for i, m in enumerate(self.movies):
            if m.name == movie_name:
                # Make sure movie is not rented before deleting
                if m.stock == m.total_stock:
                    del self.movies[i]
                    return True
                    return False
        return False

    def add_customer(self, customer):

    def remove_customer(self, customer_name):
        for i, c in enumerate(self.customers):
            if c.name == customer_name:
                del self.customers[i]
                return True
        return False

    def get_customer(self, customer_name):
        for c in self.customers:
            if c.name == customer_name:
                return c
        return None

    def get_movie(self, movie_name):
        for m in self.movies:
            if m.name == movie_name:
                return m
        return None

    def rent_movie(self, movie_name, customer_name, num):
        movie = self.get_movie(movie_name)
        customer = self.get_customer(customer_name)
        if movie and customer:
            if movie.rent_movie(num) and customer.can_rent_movie(movie):