SHARE
TWEET

Untitled

a guest Sep 19th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Employee:
  2.     num_of_emps = 0
  3.     raise_amt = 1.04
  4.  
  5.     def __init__(self, first, last, pay):
  6.         self.first = first
  7.         self.last = last
  8.         self.email = first + '.' + last + '@example.com'
  9.         self.pay = pay
  10.  
  11.         Employee.num_of_emps += 1
  12.  
  13.     def fullname(self):
  14.         return '{} {}'.format(self.first, self.last)
  15.  
  16.     def apply_raise(self):
  17.         self.pay = int(self.pay * self.raise_amt)
  18.  
  19.     @classmethod
  20.     def set_raise_amount(cls, amount):
  21.         cls.raise_amt = amount
  22.  
  23.     @classmethod
  24.     def from_string(cls, emp_str):
  25.         first, last, pay = emp_str.split('-')
  26.         return cls(first, last, pay)
  27.  
  28.     @staticmethod
  29.     def is_workday(day):
  30.         if day.weekday() == 5 or day.weekday == 6:
  31.             return False
  32.         return True
  33.  
  34.     def __repr__(self):
  35.         return "Employee('{}', '{}', '{}')".format(self.first, self.last, self.pay)
  36.  
  37.     def __str__(self):
  38.         return '{} - {}'.format(self.fullname(), self.email)
  39.  
  40.     #More dunder/magic methods
  41.     def __add__(self, other):
  42.         return self.pay + other.pay
  43.  
  44.     def __len__(self):
  45.         return len(self.fullname())
  46.  
  47.  
  48. # Method resolution order
  49. class Developer(Employee):
  50.     raise_amt = 1.10
  51.  
  52.     def __init__(self, first, last, pay, prog_lang):
  53.         super().__init__(first, last, pay)
  54.         # Employee.__init__(self, first, last, pay) MULTIPLE INHERITANCE
  55.         self.prog_lang = prog_lang
  56.  
  57.  
  58. class Manager(Employee):
  59.     def __init__(self, first, last, pay, employees=None):
  60.         super().__init__(first, last, pay)
  61.         if employees is None:
  62.             self.employees = []
  63.         else:
  64.             self.employees = employees
  65.  
  66.     def add_emp(self, emp):
  67.         if emp not in self.employees:
  68.             self.employees.append(emp)
  69.  
  70.     def remove_emp(self, emp):
  71.         if emp in self.employees:
  72.             self.employees.remove(emp)
  73.  
  74.     def print_emp(self):
  75.         for emp in self.employees:
  76.             print('==>', emp.fullname())
  77.  
  78.  
  79.  
  80. dev_1 = Employee('Corey', 'Schafer', 50000)
  81. dev_2 = Employee('Test', 'Bran', 60000)
  82.  
  83. print(dev_1)
  84. print(dev_1.__repr__())
  85.  
  86.  
  87.  
  88. # emp_str_1 = 'John-Doe-7000'
  89. # emp_str_2 = 'Lara-Johnson-30000'
  90. # emp_str_3 = 'John-Tatcher-9000'
  91.  
  92. # emp_str = Employee.from_string(emp_str_3)
  93.  
  94. # print(emp_str.email)
  95.  
  96.  
  97. # dev_1 = Developer('Corey', 'Schafer', 50000, 'Python')
  98. # dev_2 = Developer('Test', 'Bran', 60000, 'Java')
  99.  
  100. # mgr_1 = Manager('Tsue', 'Gina', 90000, [dev_1])
  101.  
  102. # print(mgr_1.email)
  103. # mgr_1.print_emp()
  104.  
  105. # isinstance(mgr_1, Developer)
  106. # isinstance(mgr_1, Manager)
  107. # isinstance(mgr_1, Employee)
  108.  
  109. # issubclass(Manager, Employee)
  110. # issubclass(Employee, Manager)
  111.  
  112.  
  113. # print(mgr_1.prog_lang)
  114.  
  115. # print(help(Developer))
  116.  
  117. # print(help(Developer))
  118.  
  119. # import datetime
  120.  
  121. # my_date = datetime.date(2016, 6, 7)
  122.  
  123. # print(Employee.is_workday(my_date))
  124. # Employee.set_raise_amount(1.05)
  125.  
  126.  
  127. # print(Employee.raise_amt)
  128. # print(emp_1.raise_amt)
  129. # print(emp_2.raise_amt)
  130.  
  131.  
  132.  
  133.  
  134. # print('I am here')
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