Question: I need help in PHP ...There is a total of (6) errors have been found in the files you have been given. Your challenge for

I need help in PHP

...There is a total of (6) errors have been found in the files you have been given. Your challenge for this assignment is to find and correct those problems so that the application runs without throwing PHP errors or providing incorrect calculations. To help narrow down your search for the bad (or missing) code, here are the (6) problems you need to address:

index.php

  1. Incorrect logic was applied in a conditional test which causes a PHP fatal error on page load
  2. A coding mistake which - when the "calculate" button is pressed - causes the following page to be blank

display_results.php

  1. A coding mistake which causes a PHP fatal error to occur when executing line 15
  2. An omission which causes the incorrect number of years to be used & displayed

future_value.php

  1. A coding mistake which causes a PHP fatal error to occur when executing line 46 of display_results.php
  2. A coding mistake which - when Compound Interest Monthly is selected - causes a wrong future value calculation (2)

The following is the code....

index.php-

Future Value Calculator

Future Value Calculator

Compound Interest Monthly

display_results.php-

// get the data from the form $investment = filter_input(INPUT_POST, 'investment', FILTER_VALIDATE_FLOAT); $interest_rate = filter_input(INPUT_POST, 'interest_rate', FILTER_VALIDATE_FLOAT); $years = filter_input(INPUT_POST, 'years', FILTER_VALIDATE_INT); $compounded_monthly = filter_input(INPUT_POST, 'compound_monthly', FILTER_VALIDATE_BOOLEAN);

// create FutureValue object $fv = new FutureValue();

// set data in FutureValue object $fv->setInvestment($investment); $fv->setYearlyInterestRate($interest_rate);

$fv->setCompoundMonthly($compounded_monthly);

// Validate the data $error_message = $fv->validate();

// if an error message exists, go to the index page if ($error_message != '') { include('index.php'); exit(); } ?> Future Value Calculator

Future Value Calculator

getInvestmentFormatted(); ?>

getYearlyInterestRateFormatted(); ?>

getYears(); ?>

getFutureValueFormatted(); ?> getCompoundMonthlyFormatted(); ?>

This calculation was done on

Future_value.php-

class FutureValue { private $investment; private $yearly_interest_rate; private $years; private $compound_monthly;

public function __construct() { $this->investment = 10000; $this->yearly_interest_rate = 4; $this->years = 10; $this->compound_monthly = false; }

public function setInvestment($investment){ $this->investment = $investment; } public function getInvestment() { return $this->investment; } public function getInvestmentFormatted() { return $this->getCurrencyFormat($this->investment); } public function setYearlyInterestRate($yearly_interest_rate){ $this->yearly_interest_rate = $yearly_interest_rate; } public function getYearlyInterestRate() { return $this->yearly_interest_rate; } private function getYearlyInterestRateFormatted() { return $this->getPercentFormat($this->yearly_interest_rate); }

public function setYears($years){ $this->years = $years; } public function getYears() { return $this->years; }

public function setCompoundMonthly($compound_monthly){ $this->compound_monthly = $compound_monthly; } public function getCompoundMonthly() { return $this->compound_monthly; } public function getCompoundMonthlyFormatted() { if ($this->compound_monthly) { return 'Yes'; } else { return 'No'; } } public function getMonths() { $months = $this->years * 12; return $months; } public function getMonthlyInterestRate() { $monthly_interest_rate = $this->yearly_interest_rate / 12; return $monthly_interest_rate; }

public function getFutureValue() { $future_value = $this->investment; if ($this->compound_monthly) { // compound monthly $months = $this->getYears(); $monthly_rate = $this->getMonthlyInterestRate(); for ($i = 1; $i <= $months; $i++) { $future_value += $future_value * $monthly_rate *.01; } } else { // compound yearly for ($i = 1; $i <= $this->years; $i++) { $future_value += $future_value * $this->yearly_interest_rate *.01; } } return $future_value; } public function getFutureValueFormatted() { return $this->getCurrencyFormat($this->getFutureValue()); }

function validate() { // validate investmnent if ( $this->investment === FALSE ) { $error_message = 'Investment must be a valid number.'; } else if ( $this->investment <= 0 ) { $error_message = 'Investment must be greater than zero.'; // validate interest rate } else if ( $this->yearly_interest_rate === FALSE ) { $error_message = 'Interest rate must be a valid number.'; } else if ( $this->yearly_interest_rate <= 0 ) { $error_message = 'Interest rate must be greater than zero.'; // validate years } else if ( $this->years === FALSE ) { $error_message = 'Years must be a valid whole number.'; } else if ( $this->years <= 0 ) { $error_message = 'Years must be greater than zero.'; } else if ( $this->years > 30 ) { $error_message = 'Years must be less than 31.'; // set error message to empty string if no invalid entries } else { $error_message = ''; }

return $error_message; }

function getCurrencyFormat($value) { $formatted_value = '$'.number_format($value, 2); return $formatted_value; }

function getPercentFormat($value) { $formatted_value = $value . '%'; return $formatted_value; } } ?>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!