Advertisement
Peileppe

ccg

Feb 21st, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.05 KB | None | 0 0
  1. """
  2. - buggy code - doesn't work properly
  3. it's an implementation of a list of objects
  4.  
  5. problem is retrieving an object out of the list
  6. since the object is referred as an address in the list
  7. the test if name not in self.list_Agent is irrelevant because the list isn't indexed by name but by a pointer
  8. the deleting a object from the list isn't possible either
  9. only adding object is possible.
  10.  
  11. This is how the list_Agent is stored - as object :
  12. [<__main__.Agent object at 0x6fc70>, <__main__.Agent object at 0x6fd10>, <__main__.Agent object at 0x6fe30>, <__main__.Agent object at 0x6fe90>, <__main__.Agent object at 0x6fe50>, <__main__.Agent object at 0x6fe70>]
  13. """
  14. class Agent(object):
  15.     def __init__(self, name, level, burnout):
  16.         self.active=True
  17.         self.name=name
  18.         self.level=level
  19.         self.burnout=burnout
  20.  
  21.     def display(self):
  22.         print "- %s is agent Tier%s with %s level of burnout" % (self.name, self.level, self.burnout)
  23.    
  24.     def levelup(self):
  25.         self.level+=1
  26.    
  27.     def fire(self,name):
  28.         self.active=False
  29.         del self # is that even working?
  30.    
  31.     def hire(self,name):
  32.         self.active=True
  33.  
  34. class Center(object):
  35.     """
  36.     Call-Center is a list of Agent
  37.     """
  38.     nb_agent=0
  39.     list_Agent=[]
  40.  
  41.     def hire(self, name):
  42.         if name not in self.list_Agent:
  43.             self.list_Agent.append(Agent(name,1,0))
  44.             self.nb_agent+=1
  45.             print "** %s has been hired" % name
  46.         else:
  47.             print "Sorry %s already in the list" % name
  48.  
  49.     def __init__(self, *list_name):
  50.         for name in list_name:
  51.             self.hire(name)
  52.    
  53.     def display(self):
  54.         print "== list of employee =="
  55.         for i in range(self.nb_agent):
  56.             self.list_Agent[i].display()
  57.        
  58.     def fire(self,name):
  59.         if name in self.list_Agent:
  60.             id=4
  61.             del self.list_Agent[id]
  62.             self.nb_agent-=1
  63.             print "** %s has been fired" % name
  64.         else:
  65.             print "Sorry %s is not in the list" % name
  66.    
  67. my_ccg=Center("Bob Preszkovic", "Jim Bishop", "Barbara O'Reilly", "Peter Munoz")
  68. my_ccg.display()
  69. my_ccg.hire("Greg")
  70. my_ccg.hire("Jim Bishop")
  71. print "---"
  72. my_ccg.display()
  73. my_ccg.fire("Greg")
  74. print "---"
  75. print my_ccg.list_Agent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement