18. Problem to create employee management system using python

In this Python oops program, we will create an employee management system using Python. This example demonstrates a basic implementation of an employee management application using Python with the help of the below-given steps.

Employee management system using Python

Steps to solve the program
  1. The Employee class represents an employee and has attributes like emp_id, name, and salary. The __init__ method initializes these attributes.
  2. It also has a method called display_details that prints the employee’s ID, name, and salary.
  3. The EmployeeManagementApp class represents the employee management application. It has an attribute called employees which is a list to store instances of the Employee class.
  4. It provides methods to add and remove employees from the application using the add_employee and remove_employee methods.
  5. The display_all_employees method iterates over the list of employees and calls the display_details method for each employee to print their details.
  6. The remaining part of the code demonstrates the usage of the employee management application:
  7. An instance of the EmployeeManagementApp class is created.
  8. Instances of the Employee class are created with different employee IDs, names, and salaries.
  9. Employees are added to the application using the add_employee method.
  10. Finally, the display_all_employees method is called to display the details of all employees in the application.

				
					class Employee:
    def __init__(self, emp_id, name, salary):
        self.emp_id = emp_id
        self.name = name
        self.salary = salary
    
    def display_details(self):
        print("Employee ID:", self.emp_id)
        print("Name:", self.name)
        print("Salary:", self.salary)

class EmployeeManagementApp:
    def __init__(self):
        self.employees = []
    
    def add_employee(self, employee):
        self.employees.append(employee)
    
    def remove_employee(self, employee):
        if employee in self.employees:
            self.employees.remove(employee)
    
    def display_all_employees(self):
        for employee in self.employees:
            employee.display_details()

# Create an instance of the EmployeeManagementApp class
app = EmployeeManagementApp()

# Add employees to the application
employee1 = Employee(1, "Robert Yates", 50000)
employee2 = Employee(2, "Kelly Smith", 60000)
employee3 = Employee(3, "Michael Potter", 55000)

app.add_employee(employee1)
app.add_employee(employee2)
app.add_employee(employee3)

# Display all employees in the application
app.display_all_employees()

				
			

Output:

				
					Employee ID: 1
Name: Robert Yates
Salary: 50000
Employee ID: 2
Name: Kelly Smith
Salary: 60000
Employee ID: 3
Name: Michael Potter
Salary: 55000
				
			

Related Articles

Python Class Structure for School Management System.

Python Class with @property decorator.

Leave a Comment