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
- The Employee class represents an employee and has attributes like emp_id, name, and salary. The __init__ method initializes these attributes.
- It also has a method called display_details that prints the employee’s ID, name, and salary.
- 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.
- It provides methods to add and remove employees from the application using the add_employee and remove_employee methods.
- The display_all_employees method iterates over the list of employees and calls the display_details method for each employee to print their details.
- The remaining part of the code demonstrates the usage of the employee management application:
- An instance of the EmployeeManagementApp class is created.
- Instances of the Employee class are created with different employee IDs, names, and salaries.
- Employees are added to the application using the add_employee method.
- 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
Write a Python Class with @property decorator.
Write a Python Class structure with module-level Import.
Create 5 different Python Classes and access them via a single class object.
Create 5 Python classes and set up multilevel inheritance among all the classes.
Set Instance variable data with setattr and getattr methods.
Python oops program with encapsulation.