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