Created
January 8, 2021 17:30
-
-
Save counterbeing/0f96a36c013381975f747ace1248c386 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Calculator | |
DAYS_PER_YEAR=365 | |
attr_accessor :years, :rate, :amount | |
def initialize(years, amount, rate) | |
@years = years | |
@rate = rate/100.0 | |
@amount = amount | |
end | |
def calculate | |
(0..days).reduce(amount) do |acc| | |
(daily_interest_rate * acc) + acc | |
end | |
end | |
private | |
def days | |
years * DAYS_PER_YEAR | |
end | |
def daily_interest_rate | |
rate/DAYS_PER_YEAR | |
end | |
end | |
puts Calculator.new(1, 5000, 70).calculate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment