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):
1000 dollars.1000 dollars and less than 5000 dollars.5000 dollars.You have four tasks, each of which will deal your balance and its interest rate.
Implement the method, SavingsAccount.interest_rate() that takes a balance as an argument.
The method should return the interest rate for the given balance.
SavingsAccount.interest_rate(200.75)
# => 0.5Implement the method, SavingsAccount.interest() that takes a balance as an argument.
The method should return the interest for the given balance.
SavingsAccount.interest(200.75)
# => 1.00375Implement the method, SavingsAccount.annual_balance_update() that takes a balance as an argument.
The method should return the balance after one year.
SavingsAccount.annual_balance_update(200.75)
# => 201.75375Implement the method, SavingsAccount.years_before_desired_balance() that takes a balance and a target balance as arguments.
The method should return the number of years it would take to reach the target balance.
balance = 200.75
target_balance = 214.88
SavingsAccount.years_before_desired_balance(balance, target_balance)
# => 14When 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.
Compound interest on the other hand is done by applying interest on a recurring basis. 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.
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):
1000 dollars.1000 dollars and less than 5000 dollars.5000 dollars.You have four tasks, each of which will deal your balance and its interest rate.
Implement the method, SavingsAccount.interest_rate() that takes a balance as an argument.
The method should return the interest rate for the given balance.
SavingsAccount.interest_rate(200.75)
# => 0.5Implement the method, SavingsAccount.interest() that takes a balance as an argument.
The method should return the interest for the given balance.
SavingsAccount.interest(200.75)
# => 1.00375Implement the method, SavingsAccount.annual_balance_update() that takes a balance as an argument.
The method should return the balance after one year.
SavingsAccount.annual_balance_update(200.75)
# => 201.75375Implement the method, SavingsAccount.years_before_desired_balance() that takes a balance and a target balance as arguments.
The method should return the number of years it would take to reach the target balance.
balance = 200.75
target_balance = 214.88
SavingsAccount.years_before_desired_balance(balance, target_balance)
# => 14When 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.
Compound interest on the other hand is done by applying interest on a recurring basis. 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.