From 8ec88135f4858f99be362157efd4ec65162a3698 Mon Sep 17 00:00:00 2001 From: zzhhaa Date: Tue, 15 Oct 2024 17:49:30 +0100 Subject: [PATCH] feat: add totalInterest prop to Mortgage class --- app/models/Mortgage.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/models/Mortgage.ts b/app/models/Mortgage.ts index 63e7e4db..17bc9bb9 100644 --- a/app/models/Mortgage.ts +++ b/app/models/Mortgage.ts @@ -35,6 +35,7 @@ export class Mortgage { monthlyPayment: number; totalMortgageCost: number; yearlyPaymentBreakdown: MortgageBreakdown; + totalInterest: number; constructor(params: MortgageParams) { this.propertyValue = params.propertyValue; @@ -51,6 +52,7 @@ export class Mortgage { this.totalMortgageCost = totalMortgageCost; this.yearlyPaymentBreakdown = this.calculateYearlyPaymentBreakdown(); + this.totalInterest = this.calculateTotalInterest(); } private calculateMortgagePrinciple() { @@ -110,4 +112,9 @@ export class Mortgage { return yearlyPaymentBreakdown; } + private calculateTotalInterest() { + const totalInterest = parseFloat((this.principal * this.interestRate * this.termYears).toFixed(2)) + console.log("Total interest: ", totalInterest) + return totalInterest + } }