#!/usr/bin/python3
#======================================================================================
# The user program (class) - 
# Creating objects of the subclasses (FullTimer and PartTimer)
# Extendinhg the superclass
#======================================================================================
class Employee:

    __companyName   = "XYZ inc."                      # static attributes
    __employeeCount = 0                               # belong to the class as a whole


    def __init__(self, title,last,first,sex,old):     # constructor
        
        self.__position  = title                      # instance attributes
        self.__lastname  = last                       # belong to each object
        self.__firstname = first
        self.__sex       = sex
        self.__age       = old
        
        Employee.__employeeCount += 1;


    @staticmethod
    def getCompanyName() :                              # static getter method
        return (Employee.__companyName)                 

    @staticmethod
    def getEmployeeCount() :                            # static getter method
        return (Employee.__employeeCount)               

    @staticmethod 
    def setCompanyName(newname) :                       # static setter method
        Employee.__companyName = newname               

    @staticmethod                                       
    def companyInfo() :                                 
        print("Company    " , Employee.__companyName)
        print("Empl count " , Employee.__employeeCount)
#or     print("Empl count " , Employee.getEmployeeCount())


    def getPosition(self) :                             # instance getter method
        return (self.__position)

    def getLastname(self) :                             # instance getter method
        return (self.__lastname)

    def getFirstname(self) :                            # instance getter method
        return (self.__firstname)

    def getSex(self) :                                  # instance getter method
        return (self.__sex)

    def getAge(self) :                                  # instance getter method
        return (self.__age)

    def setPosition(self, title) :                      # instance setter method
        self.__position = title

    def setLastname(self, last) :                       # instance setter method
        self.__lastname = last

    def setFirstname(self, first) :                     # instance setter method
        self.__Firstname = first

    def setSex(self, sex) :                             # instance setter method
        self.__sex = sex

    def setAge(self, old) :                             # instance setter method
        self.__age = old

    def getFullname (self) :                            # instance method
        if self.__sex == 'M':
            salutation = "Mr."
        else:
            salutation = "Ms."
        name  = salutation +" "+ self.__firstname +" "+ self.__lastname     # belongs to each object
        return (name)


    def __str__(self) :                                                     # instance method
        data  = "    Company "  + Employee.__companyName + \
                "\t Position: " + self.__position  + \
                "\t Name: "     + self.__firstname +  " " + self.__lastname + \
                "\t Sex: "      + self.__sex       + \
                "\t Age: "      + str(self.__age)
        return (data)



#======================================================================================
# The FullTimer class - 
# Extends the Employee class
#======================================================================================
class FullTimer(Employee):                            # FullTimer class extends Employee superclass

    __pensionPlan = True;                                           #add class attributes
     
    def __init__(self, title, last, first, x, old, sal, vac):       #constructor    
     
        super().__init__(title, last, first, x, old)                #call the superclass constructor
        self.__salary       = sal                                   #add instance attributes                                
        self.__vacationDays = vac 

    def __str__(self) :                       
        data  = super().__str__()                                   #call the superclass __str__()
        data += "\t salary: "         + str(self.__salary) + \
                "\t vacation days: "  + str(self.__vacationDays)                
        return (data)


#======================================================================================
# The PartTimer class - 
# Extends the Employee class
# Override the getFullname() method
#======================================================================================
class PartTimer(Employee):                            # PartTimer class extends Employee superclass

    __pensionPlan = False;                                          #add class attributes
     
    def __init__(self, title, last, first, x, old, hours, rate):    #constructor    
     
        super().__init__(title, last, first, x, old)                #call the superclass constructor
        self.__numHours   = hours                                   #add instance attributes                                
        self.__hourlyRate = rate 

    def getFullname (self) :                                        # override the getFullname
        if self.getSex() == 'M':                                    # of the Employee class
            salutation = "Mr."
        else:
            salutation = "Ms."
        name  = salutation +" "+ self.getFirstname() +" "+ self.getLastname()     
        name += "\t Sex="  +" "+ self.getSex() + " (temp)"  
        return (name)

    def __str__(self) :                                             # instance method
        data  = super().__str__()                                   #call the superclass __str__()
        data += "\t # of hours: "  + str(self.__numHours) + \
                "\t hourly rate: " + str(self.__hourlyRate)                
        return (data)


#======================================================================================
# The user program (class) - 
# Creating objects of the subclasses (Employee, FullTimer and PartTimer)
#======================================================================================

class EmployeeUse:

    print("Content-type: text/html \n")                 #required HTTP response header

    e0 = Employee("Pres","Obama","Barak","M",50)  

    e1 = FullTimer("Dir","Sultan","Sam","M",48,45000,12)  
    e2 = FullTimer("Mgr","Smith","Mary","F",35,40000,12)  
    e3 = FullTimer("Sec","Stevens","Bob","M",28,35000,10)

    e4 = PartTimer("NE","Williams","Bill","M",45,30,25)  
    e5 = PartTimer("NE","Johnson","Joan","F",32,25,22) 
                                               
    print(Employee.getCompanyName())                    #access it thru Employee
    print(FullTimer.getCompanyName())                   #or FullTimer or PartTimer
    print(PartTimer.getCompanyName())                   #(companyName is inherited)
                                                   
    count = Employee.getEmployeeCount()                 #You can call this method
    print("Number employees:" , count)                  #on the Employee class

    count = FullTimer.getEmployeeCount()                #or you can also call it
    print("Number employees:" , count);                 #on the FullTimer class
    count = PartTimer.getEmployeeCount()                #or the PartTimer class    
    print("Number employees:" , count)                  #(method is inherited)

    print(e0.getFullname())                             #getFullname() method
    print(e1.getFullname())                             #is inherited from 
    print(e2.getFullname())                             #the Employee class
    print(e3.getFullname())                             #to Fulltimer class,
    print(e4.getFullname())                             #and PartTimer class.
    print(e5.getFullname())                             #but it is overwritten 
                                                        #in the FullTimer class
    print()
    print(e0)                                           #call the __str__()  
    print(e1 , "\n" , e2 , "\n" , e3)                     
    print(e4 , "\n" , e5)                               
    print()                                    
                                               
                                               

                                               
#=== link to see the python code =================================================
import os, sys
sys.path.insert(0,'/home/s/sultans/web/python/demo')
import zCode                          #import func to display the Python code
filename = os.path.abspath(__file__)  #get absolute file name 
zCode.display(filename)               #call it
#=================================================================================