Task:
- Implement the following problem
- Write a unit test for the implementation
We want to implement an income calculator that, given a compensation package and a start date, returns the income earned in each year up to the current date.
The input is:
- Start date (SimpleDate)
- Base salary per year (int)
- RSU per year (int)
- Sign on bonus, only once (int)
SimpleDate is my own implementation of Date. It has these fields:
- SimpleDate:
- month: int
- year: int
You can also use SimpleDate.now() to get the current date.
Example: Given these values
- Base salary: 120,000
- Annual RSU: 60,000
- One-time Sign on: 25,000
- Start date: 02/2021
- Current date: 02/2023
The calculator should return:
- 2021: 190,000 (11 months income, including February plus sign on)
- 2022: 180,000 (12 months income)
- 2023: 15,000 (only January, excluding February)
This problem asks you to build a year-by-year income calculator for a compensation package with base salary, annual RSU, and a one-time sign-on bonus. The key is to split the time range from the start date to the current date into partial and full years, then compute each year’s income based on the number of included months. A clean solution usually iterates across years, handles the first and last year carefully, and adds the sign-on bonus only once in the starting year.