Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Enum help
#3
Thanks for replying

from abc import ABC,abstractmethod
import itertools
from enum import Enum, auto

class Employee(ABC):

    
    employee_id = itertools.count(1000)
    

    def __init__(self,first_name,last_name,id_number,hours_worked,total_wage = 0,Position position):
        self.set_first_name(first_name)
        self.set_last_name(last_name)
        self.id_number = next(self.employee_id)
        self.set_hours_worked(hours_worked)
        self.total_wage = self.calculate_pay()

    def get_first_name(self):
        return self.first_name 

    def get_last_name(self):
        return self.last_name

    def get_id_number(self):
        return self.id_number

    def get_hours_worked(self):
        return self.hours_worked

    def set_first_name(self,first_name):
        if not first_name:
            raise Exception("FIRSTNAME FIELD CANNOT BE EMPTY!")
        self.first_name = first_name

    def set_last_name(self,last_name):
        if not last_name: 
            raise Exception("LAST NAME FIELD CANNOT BE EMPTY!")
        self.last_name = last_name

    def set_id_number(self,id_number):
        self.id_number = id_number

    def set_hours_worked(self,hours_worked):
        if hours_worked < 0:
            raise Exception("HOURS CANNOT BE LESS THAN 0!")
        self.hours_worked = hours_worked
    
    @abstractmethod
    def calculate_pay(self):
        pass           

    def __str__(self):
        return '\nName: {} \nLastName: {} \nId Number: {} \nHours Worked: {} \nTotal Pay: {} \nPosition: {}'.format(self.first_name, self.last_name,self.id_number,self.hours_worked,self.calculate_pay(),self.position)     

class Operator(Employee):
    
    amount_per_hour = 9.80

    def __init__(self,first_name,last_name,id_number,hours_worked,total_wage = 0,position):
        super().__init__(first_name,last_name,id_number,hours_worked,total_wage = 0,position)

    def calculate_pay(self):
        return round(self.amount_per_hour * self.hours_worked)

    def __str__(self):
        return super(Operator,self).__str__()


class Supervisor(Employee):
    amount_per_hour = 12.10 

    def __init__(self,first_name,last_name,id_number,hours_worked,total_wage = 0,position):
        super().__init__(first_name,last_name,id_number,hours_worked,total_wage = 0,position)

    def calculate_pay(self):
        return round(self.amount_per_hour * self.hours_worked)

    def __str__(self):
        return super(Supervisor,self).__str__()  

class Manager(Employee):
    

    def __init__(self,first_name,last_name,id_number,hours_worked,total_wage = 0,position):
         super().__init__(first_name,last_name,id_number,hours_worked,total_wage = 0,position)

    def calculate_pay(self):
        return 4000

    def __str__(self):
        return super(Manager,self).__str__()    

class Position(Enum):
    OPERATOR = "operator"
    SUPERVISOR = "supervisor"
    MANAGER = "manager"


def main():

    o = Operator("Kevin","ward",0,39,0,Position.SUPERVISOR)
    print(o)




main()
Error:
Traceback (most recent call last): File "C:\Users\Sephiroth\Desktop\thonny\Employee3.py", line 11 def __init__(self,first_name,last_name,id_number,hours_worked,total_wage = 0,Position position):
Reply


Messages In This Thread
Enum help - by SephMon - Nov-18-2021, 12:13 PM
RE: Enum help - by Larz60+ - Nov-18-2021, 11:09 PM
RE: Enum help - by SephMon - Nov-19-2021, 12:00 AM
RE: Enum help - by Yoriz - Nov-19-2021, 09:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable sorting methods for Enum DataClasses koen 1 864 May-30-2023, 07:31 PM
Last Post: deanhystad
  Alarm system with state, class, enum. Frankduc 0 1,340 May-04-2022, 01:26 PM
Last Post: Frankduc
Question Having trouble writing an Enum with a custom __new__ method stevendaprano 3 4,411 Feb-13-2022, 06:37 AM
Last Post: deanhystad
  enum from typelib Erhy 2 2,215 Jan-26-2019, 05:37 PM
Last Post: Erhy
  Python error? Enum and strings tycarac 3 3,677 Dec-15-2018, 10:39 AM
Last Post: tycarac

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020