0% found this document useful (0 votes)
16 views4 pages

Class EmployeeManagementSystem: PDF

Python project

Uploaded by

anaditaprasad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Class EmployeeManagementSystem: PDF

Python project

Uploaded by

anaditaprasad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

class EmployeeManagementSystem:

def __init__(self):
self.employees = {} # Dictionary to store employee details
self.department_wise_employees = {} # Dictionary to store department-wise employees
self.employee_stack = [] # Stack to add multiple employees
self.employee_queue = [] # Queue to manage employees who are leaving

def add_employee(self, id, name, age, department, salary):


if id not in self.employees:
self.employees[id] = {
"name": name,
"age": age,
"department": department,
"salary": salary
}
if department not in self.department_wise_employees:
self.department_wise_employees[department] = []
self.department_wise_employees[department].append(id)
else:
print("Employee with ID", id, "already exists.")

def search_employee(self, id):


if id in self.employees:
return self.employees[id]
else:
return "Employee not found."

def sort_employees_by_salary(self):
sorted_employees = sorted(self.employees.items(), key=lambda x: x[1]["salary"],
reverse=True)
return sorted_employees
def remove_duplicate_employees(self, employee_list):
unique_employees = set()
for employee in employee_list:
unique_employees.add(tuple(employee.items()))
return unique_employees

def add_multiple_employees(self, employees):


for employee in employees:
self.employee_stack.append(employee)

def display_employee_stack(self):
return self.employee_stack[::-1]

def add_employee_to_queue(self, id):


if id in self.employees:
self.employee_queue.append(id)
else:
print("Employee not found.")

def display_employee_queue(self):
return self.employee_queue

def main():
ems = EmployeeManagementSystem()

while True:
print("\nEmployee Management System\n")
print("1. Add New Employee")
print("2. Search Employee by ID")
print("3. Sort Employees by Salary")
print("4. Remove Duplicate Employees")
print("5. Department-wise Employee Details")
print("6. Add Multiple Employees using Stack")
print("7. Display Employee Stack")
print("8. Add Employee to Queue")
print("9. Display Employee Queue")
print("10. Exit")

choice = input("Enter your choice: ")

if choice == "1":
id = input("Enter employee ID: ")
name = input("Enter employee name: ")
age = input("Enter employee age: ")
department = input("Enter employee department: ")
salary = float(input("Enter employee salary: "))
ems.add_employee(id, name, age, department, salary)
elif choice == "2":
id = input("Enter employee ID: ")
print(ems.search_employee(id))
elif choice == "3":
print(ems.sort_employees_by_salary())
elif choice == "4":
employee_list = [
{"id": "1", "name": "John", "age": 30, "department": "HR", "salary": 50000.0},
{"id": "2", "name": "Jane", "age": 25, "department": "Marketing", "salary": 60000.0},
{"id": "1", "name": "John", "age": 30, "department": "HR", "salary": 50000.0},
]
print(ems.remove_duplicate_employees(employee_list))
elif choice == "5":
print(ems.department_wise_employees)
elif choice == "6":
employees = [
{"id": "3", "name": "Bob", "age": 35, "department": "IT", "salary": 70000.0},
{"id": "4", "name": "Alice", "age": 28, "department": "Finance", "salary": 55000.0},
]
ems.add_multiple_employees(employees)
elif choice == "7":
print(ems.display_employee_stack())
elif choice == "8":
id = input("Enter employee ID: ")
ems.add_employee_to_queue(id)
ems.add_employee_to_queue(id)
elif choice == "9":
print(ems.display_employee_queue())
elif choice == "10":
break
else:
print("Invalid choice. Please try again.")

if __name__ == "__main__":
main()

You might also like