Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Question 6 (11 Points)
- Write a class Cafe representing a real world café. Since all good cafés have an owner and a name,
- your Cafe class has to be able to keep track of a café’s owner and her name. For example, Jens
- could own a café called “The Caffeine Grenade” and Helge could own a café called “Tonton Tubby’s
- Teapot”. Additionally, a café is in either of the two states: open or closed.
- The class Cafe shall - apart from its constructor - have three methods called, open, is_accessible,
- and change_owner.
- When newly created, a café receives a name and the name of the owner. Initially, a café is closed.
- After opening a café (with the open method) its state shall change from closed to open. In case
- a café gets a new owner, its state changes automatically to closed no matter in which state it was
- before and the name of its owner is set to the new owner’s name.
- The method is_accessible should print out the state of the café. Example output could be
- '<name> is not opened yet.' (closed) and 'Welcome to <name>' (open).
- Implement the class Cafe, including a constructor, the open method, the is_accessible method,
- and the change_owner method.
- Create two Cafe objects in the bottom of your solution file. Demonstrate that their state changes
- after they are opened and after their owners change.
- Make sure that all methods have an explanatory docstring.
- Here is an example of the intended behavior:
- >>> cafe_chez_michelle = Cafe('Cheese Cake Heaven', 'Michelle')
- >>> cafe_chez_rafael = Cafe('Cookie Monster', 'Rafael')
- >>> cafe_chez_michelle.is_accessible()
- 3
- Michelle's Cheese Cake Heaven is not opened yet.
- >>> cafe_chez_rafael.is_accessible()
- Rafael's Cookie Monster is not opened yet.
- >>> cafe_chez_michelle.open()
- >>> cafe_chez_michelle.is_accessible()
- Welcome to Cheese Cake Heaven
- >>> cafe_chez_rafael.is_accessible()
- Rafael's Cookie Monster is not opened yet.
- >>> cafe_chez_michelle.change_owner('Lena')
- >>> cafe_chez_michelle.is_accessible()
- Lena's Cheese Cake Heaven is not opened yet.
- mit svar indtil videre
- class Cafe:
- def __init__(self, name, owner):
- self.name = name
- self.owner = owner
- def open(self):
- self.open = open
- if self.open == open
- def is_accessible(self):
- if self.open == True:
- print("Welcome to" + self.name)
- else:
- print(self.name + " is not open yet")
- def change_owner(self, new_owner):
- self.owner = new_owner
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement