This repository presents the solution I developed for the Citibank coding challenge. I completed this challenge on 22 June 2023, as part of my interview for the role of Architecture Lead.
A piece of simple library code that accepts a salary in pounds and pence, and returns the amount of tax that is due, in pounds and pence.
Tax is applied in bands.
- 0 - 10,000: 1.89%
- 10,000 - 20,000: 2.5%
- 20,000 - 50,000: 4.75%
- 50,000 - 100,000: 8.25%
- > 100,000: 10.5%
Bands are not cumulative - ie. a salary of 15,000 falls in the 2.5% band, therefore tax due is 2.5% × 15,000.
- Code must be production ready, using core Java.
- Assume that the library code will be used by another team in their application.
- Work as you would if you were writing this as part of your day job.
- You may make use of resources on the Internet, e.g. Java API, Stack Overflow, etc.
BigDecimal
is a good choice for representing money.- The floor of a band is inclusive. The ceiling of a band is exclusive. For example, a salary of 10,000 falls in the 10,000 - 20,000 band.
- Round
HALF_UP
to the nearest penny. - I didn't ask about negative salaries, but I assume that they are not allowed.
- Real world code would have logging, but I didn't add them to the solution because they weren't required.
The project requires JDK 17. It was built and tested with Eclipse Temurin™. It bundles Gradle Wrapper to simplify the build process.
./gradlew build
To run the tests, run:
./gradlew test
To rerun the tests when all tasks are up-to-date, run:
./gradlew --no-build-cache cleanTest test
This project uses Adarsh Ramamurthy's Gradle Test Logger Plugin to produce more readable test output.
- Implemented the band selection logic using
NavigableMap#floorEntry
andNavigableMap#ceilingEntry
as suggested during the interview. - Throw an
IllegalArgumentException
when the salary is negative. - Simplified tests by using
ParameterizedTest
to test tax calculation for each band. - I wrote this README with my recollection of the events, so it might not be 100% accurate.
- I've added GitHub Actions to run the tests on every push and pull request.
- Dependabot was enabled to keep dependencies up-to-date