SHARE
TWEET

inheritence

apl-mhd May 27th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import datetime
  2.  
  3. class Employee:
  4.  
  5.  
  6.  
  7.     raiseAmount  = 1.04
  8.  
  9.  
  10.  
  11.     def __init__(self,first, last, pay):
  12.  
  13.  
  14.         self.first = first
  15.         self.last = last
  16.         self.pay = pay
  17.  
  18.         self.email = first +'.'+last + '@mail.com'
  19.  
  20.  
  21.  
  22.     def fullName(self):
  23.  
  24.  
  25.         return '{} {}'.format(self.first, self.last)
  26.  
  27.  
  28.     def apply_rise(self):
  29.  
  30.         self.pay = int(self.pay * self.raiseAmount)
  31.  
  32.  
  33. class Developer(Employee):
  34.  
  35.     raiseAmount = 1.10
  36.  
  37.     def __init__(self, first, last, pay, prog_lang):
  38.  
  39.         super().__init__(first,last,pay)
  40.         self.prog_lang = prog_lang
  41.  
  42.  
  43. class Manager(Employee):
  44.  
  45.     def __init__(self, first, last, pay, employees = None):
  46.  
  47.          super().__init__(first,last,pay)
  48.  
  49.          if employees is None:
  50.              self.employees = []
  51.          else:
  52.              self.employees = employees
  53.  
  54.  
  55.     def add_emp(self, emp):
  56.  
  57.         if emp not in self.employees:
  58.  
  59.                 self.employees.append(emp)
  60.  
  61.     def remove_emp(self, emp):
  62.  
  63.         if emp not in self.employees:
  64.             self.employees.remove(emp)
  65.  
  66.     def print_emp(self):
  67.         for emp in self.employees:
  68.  
  69.             print('-->', emp.fullName())
  70.  
  71.  
  72. x = Developer('Orin', 'Sabi', 50000, 'python')
  73.  
  74. y = Developer('Apel', 'sabi',12000, 'asembly')
  75.  
  76. mgr = Manager('admin', 'super',120000,[x])
  77.  
  78.  
  79.  
  80. mgr.print_emp()
  81.  
  82.  
  83.  
  84. print(x.prog_lang)
  85. print(x.email)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top