Object-oriented analysis baked sweet potato project

1  # OOA baked sweet potatoes 
2  
. 3  # 1. abstract class 
4  # 1.1 Human 
5  # 1.2 Melon 
. 6  
. 7  
. 8  # analysis of human properties and methods inside 
9  # attributes: name, sex, age bake 
10  # METHODS: Roasted sweet potatoes the method of adding seasonings 
. 11  
12 is  # melon attributes and methods 
13  # attributes: state baked sweet potatoes, sweet potatoes baked time, condiments list 
14  # : None 
15  
16  
. 17  class the Person (Object):
 18 is      DEF  the __init__ (Self, name, Sex, roast_age):
 . 19          the self.name = name
 20 is         = self.sex Sex
 21 is          self.roast_age = roast_age
 22 is      # baked sweet potatoes The method 
23 is      DEF Roast (Self, Time, current_sweet_potato):
 24          # Review baked sweet potatoes total time of 
25          current_sweet_potato.roast_time + = Time
 26 is          # The baked sweet potatoes time, baked sweet potatoes set state 
27          IF current_sweet_potato.roast_time> 10 :
 28              # modified sweet potatoes baked state 
29              current_sweet_potato.roast_status = " burned up " 
30          elif current_sweet_potato.roast_time>. 8:   # the time range [9-10] 
31             # Modify baked sweet potatoes state 
32              current_sweet_potato.roast_status = " baked " 
33 is          elif current_sweet_potato.roast_time>. 5:   # time [6-8] 
34              # modified sweet potatoes baked state 
35              current_sweet_potato.roast_status = " half-baked " 
36          the else :
 37              # modified sweet potatoes baked state 
38 is              current_sweet_potato.roast_status = " raw " 
39      DEF add_condiment (Self, condiment, current_sweet_potato):
 40          # add seasoning sauce to list 
41         current_sweet_potato.condiment_list.append (Condiment)
 42 is  
43 is      # view potato state 
44 is      # DEF show_sweet_potato (Self, current_sweet_potato): 
45      #      Print (current_sweet_potato) 
46 is      DEF  __str__ (Self):
 47          return  " Name:% s Gender:% s age roast : D% " % (the self.name, self.sex, self.roast_age)
 48  
49  
50  class SweetPotato (Object):
 51 is      DEF  the __init__ (Self):
 52 is          # baked sweet potatoes state 
53 is          self.roast_status = " raw "
54          # baked sweet potatoes time 
55          self.roast_time = 0
 56 is          # condiments attribute list -> add seasoning storage 
57 is          self.condiment_list = List ()
 58  
59      DEF  __str__ (Self):
 60          IF self.condiment_list:
 61 is              # code execution this description, there are a list of seasoning condiments information 
62              # baked potato [tomato sauce, cumin] 
63              # the seasoning listing translated into strings 
64              # MSG = self.roast_status + "potato" + STR (self.condiment_list) 
65              # string using the string concatenation operation, the list of translated into strings 
66              condiment_str = " , ".join (self.condiment_list)
 67              # Print (condiment_str, type (condiment_str)) 
68              MSG = self.roast_status + " potato " + " [ " + condiment_str + " ] " 
69              return MSG
 70          the else :
 71 is              # No dressing 
72              return self.roast_status + " potato " 
73 is  
74  Print ( " ============ preparing a potato ========== " )
 75 sweet_potato = SweetPotato ()
 76 Print (sweet_potato)
 77  Print ( " ============ baked sweet potatoes ready to find a master ============== " )
 78 the Person = the Person ( " Old Wang " , " M " , 20 )
 79  Print (the Person)
 80  Print ( " ============ to bake three minutes ========== " )
 81 person.roast (. 3 , sweet_potato)
 82  Print (sweet_potato)
 83  Print ( " ============ bake three minutes ========== " )
 84 person.roast (. 3, Sweet_potato)
 85  Print (sweet_potato)
 86  Print ( " ============ bake three minutes ========== " )
 87 person.roast (. 3 , sweet_potato)
 88  Print (sweet_potato)
 89  Print ( " ============ Add seasoning ========== " )
 90 person.add_condiment ( " ketchup " , sweet_potato)
 91 the Person. add_condiment ( " cumin " , sweet_potato)
 92  Print (sweet_potato)

 

Guess you like

Origin www.cnblogs.com/youliang-null/p/12660908.html