Restaurant Class Hierarchy

Implement a class Restaurant with basic attributes like name, location, and cuisine. Then create child classes FastFoodRestaurant, FineDiningRestaurant, Cafe, each having unique methods and attributes.

Example 1:

Input: FastFoodRestaurant('McDonald's', 'New York', 'Fast Food', 'Burger') 
Output: "McDonald's is a Fast Food restaurant in New York. They are known for their Burger."

Example 2:

Input: Cafe('Starbucks', 'Seattle', 'Coffee', 'Cappuccino') 
Output: "Starbucks is a coffee shop in Seattle. They are known for their Cappuccino."

Implement a unique method known_for in each of the child classes that returns the respective specialty of the restaurant.

class Restaurant:
    def __init__(self, name, location, cuisine):
        self.name = name
        self.location = location
        self.cuisine = cuisine

class FastFoodRestaurant(Restaurant):
    def __init__(self, name, location, cuisine, specialty):
        super().__init__(name, location, cuisine)
        self.specialty = specialty

    def known_for(self):
        return f"{self.name} is a {self.cuisine} restaurant in {self.location}. They are known for their {self.specialty}."

class Cafe(Restaurant):
    def __init__(self, name, location, cuisine, specialty):
        super().__init__(name, location, cuisine)
        self.specialty = specialty

    def known_for(self):
        return f"{self.name} is a {self.cuisine} shop in {self.location}. They are known for their {self.specialty}."

# Test the classes
restaurant1 = FastFoodRestaurant('McDonald\'s', 'New York', 'Fast Food', 'Burger')
print(restaurant1.known_for())

restaurant2 = Cafe('Starbucks', 'Seattle', 'Coffee', 'Cappuccino')
print(restaurant2.known_for())

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!