Creating a simple tool to capture employees and calculate pay rises


The program is a basic employee management system defined across two files. It allows for the creation of employee profiles, assessing retirement eligibility based on years of employment, and applying a 10% pay raise to an employee's salary.

  1. employee.py is a module that contains the definition of the employees class.

  2. Inside the employees class, the __init__ method initialises four attributes: name, role, salary, and years_employed.

  3. The retirement method checks the years_employed attribute. If it's 10 or more, it prints that the employee can retire; otherwise, it states the employee cannot retire.

  4. The payrise method calculates a 10% increase in the employee's salary and updates the salary attribute.

  5. In main.py, the employees class is imported from the employee.py module.

  6. The main function is defined, which contains the main logic of the program.

  7. Inside the main function, two instances of the employees class are created: employee1 and employee2.

  8. The program then prints the name and salary of employee2.

  9. It displays the current salary of employee1.

  10. The payrise method is called on employee1 to increase their salary by 10%.

  11. The new salary of employee1 is printed, reflecting the pay rise.

  12. The if __name__ == "__main__": statement checks if main.py is being run as the main program.

  13. If main.py is the main program, the main function is executed, running the logic defined within it.

  14. The output when main.py is executed:
Employee 2 name: Roger
Employee 2 salary: 67800.21
Employee 1 salary: 121074.40
Employee 1 receives 10% payrise, new salary: 133181.84

Challenges


As a challenge add the following functionality to employees.py:

display_info(self):
A method to display all the information about an employee in a formatted manner of your choice.

change_role(self, new_role, new_salary):
Change the role of an employee and adjust their salary accordingly.

years_until_retirement(self):
Calculate and return the number of years until the employee can retire, based on 10 years required to retire.

Feel free to email me for solutions or if you are stuck with anything.

employees.py


class employees:
    def __init__(self, name, role, salary, years_employed):
        self.name = name
        self.role = role
        self.salary = salary
        self.years_employed = years_employed

    def retirement(self):
        if self.years_employed >= 10:
            print("{} can retire.".format(self.name)) 
        else:
            print("{} can not retire.".format(self.name))

    def payrise(self):
        self.salary = ((self.salary/100) * 10) + self.salary

main.py


from employees import employees

def main():
    employee1 = employees("Alex", "Director", 121074.40, 12)
    employee2 = employees("Roger", "Clerk 1", 67800.21, 8)

    print("Employee 2 name: {}".format(employee2.name))
    print("Employee 2 salary: {:.2f}".format(employee2.salary))

    print("Employee 1 salary: {:.2f}".format(employee1.salary))
    employee1.payrise()
    print("Employee 1 receives a 10% payrise, new salary: {:.2f}".format(employee1.salary))

if __name__ == "__main__":
    main()