PHP website language Metro Bank Mortgage Calculator You\'ve been hired to do som
ID: 3875413 • Letter: P
Question
PHP website language
Metro Bank Mortgage Calculator
You've been hired to do some programming for Metro Bank. They want you to create a program to calculate loan payments. The user will enter the amount of money to borrow from the bank, the annual interest rate percentage (that will be compounded monthly) and the number of years to pay back the loan. The program will then display the monthly payment and the total amount of interest that will be paid.
Formulas & Code Specifications
Here are the formulas you will use.
Periodic Payment:
Let
A = amount of the loan
r = interest rate per period (for this calculation, 1 period is 1 month)
n = the number of periods (i.e. the number of months)
Then the formula to find the monthly payment is:
Remember, when doing calculations with percentages, you need to use the decimal equivalent. So given a percentage rate of 7.5% you want to use the value 0.075.
Total Interest Paid:
Let
P = the monthly payment
n = the number of months
A = amount of the loan
Then the formula to find the total interest is:
Total Interest = nP - A
How to Get Started:
Download the code skeleton LoanCal.php bellow
/**
* This is the loan (mortgage) calculator....
*/
?>
Product Discount Calculator
Loan Calculator
//Loan amount
$loanAmount = $_REQUEST['loan_amount'];
//Monthly rate
$annualRate = $_REQUEST['annual_rate'];
//Months in the loan period
$periodInYears = $_REQUEST['years'];
echo "Loan amount: $loanAmount
";
echo "Annual Rate: $annualRate
";
echo "Years in the loan periond: $periodInYears
";
if ($loanAmount && $annualRate && $periodInYears) { // Check if these values are valid.
$monthRate = $annualRate / 12 / 100;
//Start to do your work here. Don't use operator '**'.
}
?>
-------------- main.css ---------------
body {
font-family: Arial, Helvetica, sans-serif;
}
h1 {
margin-top: 0;
color: navy;
}
label {
width: 10em;
float: left;
padding-right: 1em;
padding-bottom: .5em;
}
input {
float: left;
width: 15em;
margin-bottom: .5em;
}
span {
padding-left: .25em;
}
input {
float: left;
margin-bottom: .5em;
}
br {
clear: left;
}
Loan Amount Interest Rate (annual %) Period in years payment -ArExplanation / Answer
<?php
namespace CentralAppsMortgageCalculator;
/**
* PHP Mortgage Calculator Class
* @author Michael Peacock
* @url www.michaelpeacock.co.uk
*/
class Calculator {
/**
* The amount borrowed
* @access private
*/
private $amountBorrowed = 0;
/**
* The interest rate
* @access private
*/
private $interestRate = 0;
/**
* Number of years to spread mortgage across
* @access private
*/
private $years = 0;
public function __construct() {}
/**
* Calculates the monthly cost of an interest only mortgage
* @return int
*/
public function calculateInterestOnlyPayment()
{
$payment = ( $this->amountBorrowed * $this->interestRate ) / 12;
return round($payment,2);
}
/**
* Calculates the monthly cost of a repayment mortgage
* @return int
*/
public function calculateRepayment()
{
$payment = ( $this->amountBorrowed * $this->interestRate ) / ( 1 - pow( ( 1 + $this->interestRate ), -$this->years ) ) / 12;
return round($payment,2);
}
/**
* Sets the amount borrowed
* @param int $amount the amount borrowed
* @return void
*/
public function setAmountBorrowed( $amount )
{
$this->amountBorrowed = $amount;
}
/**
* Sets the interest rate to calculate against
* @param int $rate the interest rate
* @return void
*/
public function setInterestRate( $rate )
{
$this->interestRate = ( $rate / 100 );
}
/**
* Set the number of years to spread the mortgage across
* @param int $years the number of years
* @return void
*/
public function setYears( $years )
{
$this->years = $years;
}
/**
* Calculate the number of monthly payments
* @return int
*/
private function numberOfPayments()
{
return $this->years / 12;
}
/**
* Calculate the amount of mortgage remaining based off how long remains
* @param int $monthsLeft the number of months left on the mortgage
* @return int
*/
private function calculateRemainingAmount( $monthsLeft )
{
return $this->calculateRepayment() * $monthsLeft;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.