Exemple #1
0
# 福尔餐馆实例
restaurant = Restaurant('Fuer', 'cheese')
# 打印餐馆的属性
print("The first restaurant is " + restaurant.restaurant_name + ".")
print("The best cuisine of " + restaurant.restaurant_name + " is " +
      restaurant.cuisine_type + ".")
# 调用类定义中的方法
restaurant.describe_restaurant()
restaurant.open_restaurant()

# 直接修改属性值
restaurant.read_number()
restaurant.number_serverd = 320
restaurant.read_number()
# 调用方法修改属性值
restaurant.set_number_serverd(500)
restaurant.read_number()
# 递增就餐人数
restaurant.increment_number_serverd(150)
restaurant.read_number()

# 冰淇淋小店实例
icecream_restaurant = IceCreamStand('Merlin ice', 'love')
# 父类方法
icecream_restaurant.describe_restaurant()
icecream_restaurant.open_restaurant()
icecream_restaurant.set_number_serverd(200)
icecream_restaurant.read_number()
# 子类特有方法
icecream_restaurant.read_icecream()
##9-10:
from restaurant import Restaurant, IceCreamStand

italian = Restaurant("nino", "italian")
italian.describe_restaurant()
italian.open_restaurant()  #this command works perfectly.

#let's see if the subclass IceCreamStand works as well.
iscream = IceCreamStand("the fainting goat", "deserts")
iscream.describe_restaurant()
iscream.open_restaurant()
iscream.ice_cream_flavors(["vanilla", "cherry", "salted carmel", "chocolate"])
#Event the IceCreamStand() subclass works perfectly.

##9-11:
import user_admin

user1 = user_admin.Administrator("mason", "karsevar", "data scientist",
                                 "seattle", "hiking")
user1.describe_user()
user1.greet_user()
#These commends from the User2 parent class work perfectly. I need to see
#if the subclass works perfectly as well.

user1.privileges.privileges = ["managing user data", "barring bad actors"]
user1.privileges.show_privileges()
#Sweet these commands worked perfectly!!!
#I can finally move onto the next chapter.

##9-12:
from administrator import Administrator