From 34859ee5940ed01e76d11d7edc1bd30803157675 Mon Sep 17 00:00:00 2001 From: locknd Date: Fri, 30 Dec 2022 20:03:50 +0500 Subject: [PATCH 1/4] Exercise 3 --- exercise3/exercise3.php.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 exercise3/exercise3.php.txt diff --git a/exercise3/exercise3.php.txt b/exercise3/exercise3.php.txt new file mode 100644 index 0000000..151c7f1 --- /dev/null +++ b/exercise3/exercise3.php.txt @@ -0,0 +1,20 @@ +function mortgagePaymentSchedule($annualInterestRate, $propertyCost, $downPayment, $loanTermMonths) { + // Расчёт месячной процентной ставки + $monthlyInterestRate = $annualInterestRate / 12; + $loanAmount = $propertyCost - $downPayment + $monthlyPayment = ($monthlyInterestRate * $loanAmount) / (1 - pow((1 + $monthlyInterestRate), -$loanTermMonths)); + + $paymentSchedule = []; + $balance = $loanAmount; + for ($i = 1; $i <= $loanTermMonths; $i++) { + $basicPayment = $monthlyPayment - ($balance * $monthlyInterestRate); + $loanPayment = $monthlyPayment - $basicPayment; + $balance -= $basicPayment; + $paymentSchedule[$i] = [ + "basicPayment" => $basicPayment, + "loanPayment" => $loanPayment, + "balance" => $balance + ]; + } + return $paymentSchedule; +} From b84dddf5a058e831fb9cf68051e64b811dde96cd Mon Sep 17 00:00:00 2001 From: locknd Date: Fri, 30 Dec 2022 20:10:47 +0500 Subject: [PATCH 2/4] Exercise 2(new) --- exercise3/exercise3.php.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/exercise3/exercise3.php.txt b/exercise3/exercise3.php.txt index 151c7f1..9b70b04 100644 --- a/exercise3/exercise3.php.txt +++ b/exercise3/exercise3.php.txt @@ -2,9 +2,11 @@ function mortgagePaymentSchedule($annualInterestRate, $propertyCost, $downPaymen // Расчёт месячной процентной ставки $monthlyInterestRate = $annualInterestRate / 12; $loanAmount = $propertyCost - $downPayment + //Эта строка вычисляет ежемесячный платеж по ипотеке $monthlyPayment = ($monthlyInterestRate * $loanAmount) / (1 - pow((1 + $monthlyInterestRate), -$loanTermMonths)); $paymentSchedule = []; + //Эти строки кода являются частью цикла for, который повторяет срок кредита в месяцах и вычисляет график платежей по ипотеке для каждого месяца $balance = $loanAmount; for ($i = 1; $i <= $loanTermMonths; $i++) { $basicPayment = $monthlyPayment - ($balance * $monthlyInterestRate); From 449706f83dfbf19857f9e5b8c52f2fca0becfbc4 Mon Sep 17 00:00:00 2001 From: locknd Date: Fri, 30 Dec 2022 20:20:45 +0500 Subject: [PATCH 3/4] Exercise 3 ( new ) --- exercise3/exercise33.php.txt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 exercise3/exercise33.php.txt diff --git a/exercise3/exercise33.php.txt b/exercise3/exercise33.php.txt new file mode 100644 index 0000000..9b70b04 --- /dev/null +++ b/exercise3/exercise33.php.txt @@ -0,0 +1,22 @@ +function mortgagePaymentSchedule($annualInterestRate, $propertyCost, $downPayment, $loanTermMonths) { + // Расчёт месячной процентной ставки + $monthlyInterestRate = $annualInterestRate / 12; + $loanAmount = $propertyCost - $downPayment + //Эта строка вычисляет ежемесячный платеж по ипотеке + $monthlyPayment = ($monthlyInterestRate * $loanAmount) / (1 - pow((1 + $monthlyInterestRate), -$loanTermMonths)); + + $paymentSchedule = []; + //Эти строки кода являются частью цикла for, который повторяет срок кредита в месяцах и вычисляет график платежей по ипотеке для каждого месяца + $balance = $loanAmount; + for ($i = 1; $i <= $loanTermMonths; $i++) { + $basicPayment = $monthlyPayment - ($balance * $monthlyInterestRate); + $loanPayment = $monthlyPayment - $basicPayment; + $balance -= $basicPayment; + $paymentSchedule[$i] = [ + "basicPayment" => $basicPayment, + "loanPayment" => $loanPayment, + "balance" => $balance + ]; + } + return $paymentSchedule; +} From aa14a4991d2a5c837f7b1a5d437d2b098ad68a2d Mon Sep 17 00:00:00 2001 From: locknd Date: Fri, 30 Dec 2022 20:28:04 +0500 Subject: [PATCH 4/4] Exercise 3 --- exercise3/exercise333.php.txt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 exercise3/exercise333.php.txt diff --git a/exercise3/exercise333.php.txt b/exercise3/exercise333.php.txt new file mode 100644 index 0000000..9b70b04 --- /dev/null +++ b/exercise3/exercise333.php.txt @@ -0,0 +1,22 @@ +function mortgagePaymentSchedule($annualInterestRate, $propertyCost, $downPayment, $loanTermMonths) { + // Расчёт месячной процентной ставки + $monthlyInterestRate = $annualInterestRate / 12; + $loanAmount = $propertyCost - $downPayment + //Эта строка вычисляет ежемесячный платеж по ипотеке + $monthlyPayment = ($monthlyInterestRate * $loanAmount) / (1 - pow((1 + $monthlyInterestRate), -$loanTermMonths)); + + $paymentSchedule = []; + //Эти строки кода являются частью цикла for, который повторяет срок кредита в месяцах и вычисляет график платежей по ипотеке для каждого месяца + $balance = $loanAmount; + for ($i = 1; $i <= $loanTermMonths; $i++) { + $basicPayment = $monthlyPayment - ($balance * $monthlyInterestRate); + $loanPayment = $monthlyPayment - $basicPayment; + $balance -= $basicPayment; + $paymentSchedule[$i] = [ + "basicPayment" => $basicPayment, + "loanPayment" => $loanPayment, + "balance" => $balance + ]; + } + return $paymentSchedule; +}