Created
June 2, 2014 20:04
-
-
Save rserur/5ebca47269b7d45a7ca4 to your computer and use it in GitHub Desktop.
Mortgage Calculator
This file contains hidden or 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 Mortgage | |
| def initialize(home_value, down_payment_percentage, apr, duration_in_years) | |
| @home_value = home_value | |
| @down_payment_percentage = down_payment_percentage | |
| @apr = apr | |
| @duration_in_years = duration_in_years | |
| end | |
| def down_payment | |
| @down_payment = @home_value * @down_payment_percentage | |
| end | |
| def duration_in_years | |
| @duration_in_years | |
| end | |
| def apr | |
| @apr | |
| end | |
| def monthly_payment | |
| @payments = @duration_in_years * 12 | |
| @interest = @apr / 12 | |
| numerator = @interest * ((1 + @interest) ** @payments) | |
| denominator = ((1 + @interest) ** @payments) - 1 | |
| @monthly_payment = (@home_value - @down_payment) * (numerator/denominator) | |
| end | |
| def total_interest_paid | |
| total_paid = @monthly_payment * @payments | |
| @total_interest_paid = total_paid - (@home_value - @down_payment) | |
| end | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment