Hone logo
Hone
Problems

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:

  1. Positive Salary: The employee's salary must be strictly greater than 0.
  2. Odd Employee ID: The employee_id must 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_id 1 (odd) and salary 5000 (> 0). Bonus is 5000 * 100 = 500000.
  • Bob has employee_id 2 (even). He does not get a bonus.
  • Charlie has employee_id 3 (odd) and salary 4500 (> 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_id 10 (even). He does not get a bonus.
  • Eve has employee_id 11 (odd), but her salary is 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_id 5 (odd) and salary 10000 (> 0). Bonus is 10000 * 100 = 1000000.
  • Grace has employee_id 7 (odd), but her salary is -500 (not > 0). She does not get a bonus.

Constraints

  • The number of employees will be between 0 and 1000.
  • employee_id will be a positive integer.
  • salary will be an integer, which can be positive, zero, or negative.
  • The output should be a list of objects, each containing employee_id and bonus. 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_id is odd, you can use the modulo operator (%). An integer n is odd if n % 2 is not equal to 0.
  • Focus on correctly implementing the conditional logic for bonus calculation.
  • Consider how to handle an empty input list of employees.
Loading editor...
plaintext