Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. Question 6 (11 Points)
  2. Write a class Cafe representing a real world café. Since all good cafés have an owner and a name,
  3. your Cafe class has to be able to keep track of a café’s owner and her name. For example, Jens
  4. could own a café called “The Caffeine Grenade” and Helge could own a café called “Tonton Tubby’s
  5. Teapot”. Additionally, a café is in either of the two states: open or closed.
  6. The class Cafe shall - apart from its constructor - have three methods called, open, is_accessible,
  7. and change_owner.
  8. When newly created, a café receives a name and the name of the owner. Initially, a café is closed.
  9. After opening a café (with the open method) its state shall change from closed to open. In case
  10. a café gets a new owner, its state changes automatically to closed no matter in which state it was
  11. before and the name of its owner is set to the new owner’s name.
  12. The method is_accessible should print out the state of the café. Example output could be
  13. '<name> is not opened yet.' (closed) and 'Welcome to <name>' (open).
  14. Implement the class Cafe, including a constructor, the open method, the is_accessible method,
  15. and the change_owner method.
  16. Create two Cafe objects in the bottom of your solution file. Demonstrate that their state changes
  17. after they are opened and after their owners change.
  18. Make sure that all methods have an explanatory docstring.
  19. Here is an example of the intended behavior:
  20.  
  21.  
  22. >>> cafe_chez_michelle = Cafe('Cheese Cake Heaven', 'Michelle')
  23. >>> cafe_chez_rafael = Cafe('Cookie Monster', 'Rafael')
  24. >>> cafe_chez_michelle.is_accessible()
  25. 3
  26. Michelle's Cheese Cake Heaven is not opened yet.
  27. >>> cafe_chez_rafael.is_accessible()
  28. Rafael's Cookie Monster is not opened yet.
  29. >>> cafe_chez_michelle.open()
  30. >>> cafe_chez_michelle.is_accessible()
  31. Welcome to Cheese Cake Heaven
  32. >>> cafe_chez_rafael.is_accessible()
  33. Rafael's Cookie Monster is not opened yet.
  34. >>> cafe_chez_michelle.change_owner('Lena')
  35. >>> cafe_chez_michelle.is_accessible()
  36. Lena's Cheese Cake Heaven is not opened yet.
  37.  
  38.  
  39.  
  40.  
  41.  
  42. mit svar indtil videre
  43.  
  44. class Cafe:
  45. def __init__(self, name, owner):
  46.  
  47. self.name = name
  48. self.owner = owner
  49.  
  50. def open(self):
  51. self.open = open
  52. if self.open == open
  53.  
  54.  
  55.  
  56. def is_accessible(self):
  57. if self.open == True:
  58. print("Welcome to" + self.name)
  59. else:
  60. print(self.name + " is not open yet")
  61.  
  62.  
  63. def change_owner(self, new_owner):
  64. self.owner = new_owner
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement