Employee Salary Management

Implement a class Employee with private attributes for name, ID, and salary. Include methods for bonuses and deductions, ensuring that the salary follows company policies and doesn’t go below a minimum (e.g., $1000).

Example 1:

Input: Salary: 3000, Bonus: 500, Deduction: 1000 
Output: 2500

Example 2:

Input: Salary: 1500, Bonus: 100, Deduction: 1800
Output: 1000 (Salary cannot go below the minimum)

Use private attributes to maintain the salary and provide methods for bonuses and deductions that follow the constraints.

class Employee:
    def __init__(self, name, ID, salary):
        self._name = name
        self._ID = ID
        self._salary = max(salary, 1000)

    def bonus(self, amount):
        self._salary += amount

    def deduction(self, amount):
        self._salary = max(self._salary - amount, 1000)

    def get_salary(self):
        return self._salary

# Test the class
employee = Employee("John", 123, 3000)
employee.bonus(500)
employee.deduction(1000)
print(employee.get_salary())  # Output: 2500

employee.deduction(1800)
print(employee.get_salary())  # Output: 1000

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!