In this exercise you'll be working with savings accounts. Each year, the balance of each savings account is updated based on the annual percentage yield (APY). The APY value depends on the amount of money in the account (its balance):
- -3.213% for a negative balance.
- 0.5% for a positive balance less than
1000
. - 1.621% for a positive balance greater or equal than
1000
and less than5000
. - 2.475% for a positive balance greater or equal than
5000
.
You have three tasks, each of which will deal with balances and their APYs.
Implement a method to calculate the APY based on the specified balance:
FloatingPointNumbers.AnnualPercentageYield(balance: 200.75m)
// 0.5f
Note that the value returned is a float
.
Implement a method to calculate the annual balance update, taking into account the APY:
FloatingPointNumbers.AnnualBalanceUpdate(balance: 200.75m)
// 201.75375m
Note that the value returned is a decimal
.
Implement a method to calculate the minimum number of years required to reach the desired balance:
FloatingPointNumbers.YearsBeforeDesiredBalance(balance: 200.75m, targetBalance: 214.88m)
// 14
Note that the value returned is an int
.