Calculate Special Bonus
Imagine you're working on a payroll system for a company. A new policy has been introduced to provide a special bonus to employees based on their performance. Your task is to develop a system that calculates this special bonus, ensuring accuracy and adherence to the new policy. This challenge will help you practice conditional logic and data manipulation, common tasks in financial and HR applications.
Problem Description
You need to calculate a special bonus for each employee based on specific criteria. For each employee, you will be given their employee_id, their name, and their salary. A special bonus is awarded only to employees who meet the following conditions:
- Positive Salary: The employee's
salarymust be strictly greater than 0. - Odd Employee ID: The
employee_idmust be an odd number.
If an employee meets both of these conditions, their special bonus will be their salary multiplied by 100. Otherwise, they receive no special bonus (a bonus of 0).
The output should be a list or collection containing the employee_id and the calculated bonus for each employee.
Examples
Example 1:
Input:
Employees:
[
{ employee_id: 1, name: "Alice", salary: 5000 },
{ employee_id: 2, name: "Bob", salary: 6000 },
{ employee_id: 3, name: "Charlie", salary: 4500 }
]
Output:
Bonuses:
[
{ employee_id: 1, bonus: 500000 },
{ employee_id: 3, bonus: 450000 }
]
Explanation:
- Alice has
employee_id1 (odd) andsalary5000 (> 0). Bonus is 5000 * 100 = 500000. - Bob has
employee_id2 (even). He does not get a bonus. - Charlie has
employee_id3 (odd) andsalary4500 (> 0). Bonus is 4500 * 100 = 450000.
Example 2:
Input:
Employees:
[
{ employee_id: 10, name: "David", salary: 7000 },
{ employee_id: 11, name: "Eve", salary: 0 }
]
Output:
Bonuses:
[
]
Explanation:
- David has
employee_id10 (even). He does not get a bonus. - Eve has
employee_id11 (odd), but hersalaryis 0. She does not get a bonus.
Example 3:
Input:
Employees:
[
{ employee_id: 5, name: "Frank", salary: 10000 },
{ employee_id: 7, name: "Grace", salary: -500 }
]
Output:
Bonuses:
[
{ employee_id: 5, bonus: 1000000 }
]
Explanation:
- Frank has
employee_id5 (odd) andsalary10000 (> 0). Bonus is 10000 * 100 = 1000000. - Grace has
employee_id7 (odd), but hersalaryis -500 (not > 0). She does not get a bonus.
Constraints
- The number of employees will be between 0 and 1000.
employee_idwill be a positive integer.salarywill be an integer, which can be positive, zero, or negative.- The output should be a list of objects, each containing
employee_idandbonus. The order of the output list does not matter.
Notes
- You will be provided with a list or collection of employee records.
- For checking if an
employee_idis odd, you can use the modulo operator (%). An integernis odd ifn % 2is not equal to 0. - Focus on correctly implementing the conditional logic for bonus calculation.
- Consider how to handle an empty input list of employees.