|
| 1 | +# Instructions |
| 2 | + |
| 3 | +In this exercise you'll be working with savings accounts. Each year, the balance of your savings account is updated based on its interest rate. |
| 4 | +The interest rate your bank gives you depends on the amount of money in your account (its balance): |
| 5 | + |
| 6 | +- 3.213% for a negative balance (balance gets more negative). |
| 7 | +- 0.5% for a positive balance less than `1000` dollars. |
| 8 | +- 1.621% for a positive balance greater than or equal to `1000` dollars and less than `5000` dollars. |
| 9 | +- 2.475% for a positive balance greater than or equal to `5000` dollars. |
| 10 | + |
| 11 | +You have four tasks, each of which will deal your balance and its interest rate. |
| 12 | + |
| 13 | +## 1. Calculate the interest rate |
| 14 | + |
| 15 | +Implement the `interest_rate()` method to calculate the interest rate based on the specified balance: |
| 16 | + |
| 17 | +```rust |
| 18 | +interest_rate(200.75) |
| 19 | +// 0.5 |
| 20 | +``` |
| 21 | + |
| 22 | + |
| 23 | +## 2. Calculate the interest |
| 24 | + |
| 25 | +Implement the `interest()` method to calculate the interest based on the specified balance: |
| 26 | + |
| 27 | +```rust |
| 28 | +interest(200.75) |
| 29 | +// 1.00375 |
| 30 | +``` |
| 31 | + |
| 32 | + |
| 33 | +## 3. Calculate the annual balance update |
| 34 | + |
| 35 | +Implement the `annual_balance_update()` method to calculate the annual balance update, taking into account the interest rate: |
| 36 | + |
| 37 | +```rust |
| 38 | +annual_balance_update(200.75) |
| 39 | +// 201.75375 |
| 40 | +``` |
| 41 | + |
| 42 | + |
| 43 | +## 4. Calculate the years before reaching the desired balance |
| 44 | + |
| 45 | +Implement the `years_before_desired_balance()` method to calculate the minimum number of years required to reach the desired balance given annually compounding interest: |
| 46 | + |
| 47 | +```rust |
| 48 | +years_before_desired_balance(200.75, 214.88) |
| 49 | +// 14 |
| 50 | +``` |
| 51 | + |
| 52 | +Note that the value returned is an integer. |
| 53 | + |
| 54 | +~~~~exercism/note |
| 55 | +When applying simple interest to a principal balance, the balance is multiplied by the interest rate and the product of the two is the interest amount. |
| 56 | +
|
| 57 | +Compound interest on the other hand is done by applying interest on a recurring basis. |
| 58 | +On each application the interest amount is computed and added to the principal balance so that subsequent interest calculations are subject to a greater principal balance. |
| 59 | +~~~~ |
0 commit comments