Image

PHP Class - Compound Interest Calculation

PHP Class - Compound interest formula in loan class calculation.

Loan class will calculate loan for class car and house which will extends Loan class.

<?php

class Loan {

  public $principle;  //Price
  public $rate;       //RoI
  public $time;       //Duration

  public function __construct($principle,$rate,$time) {
    $this->principle  = $principle;
    $this->rate      = $rate;
    $this->time      = $time;
  }
  public function calculate() {
    // Calculate compound interest 
    return $this->principle * (pow((1 +$this->rate / 100), $this->time)); 
  }
}

// Class Car
class Car extends Loan {
  
}

// Class House
class House extends Loan {
  
}


//Car class calculation
$objCar = new Car(10000, 10.25,5);
echo "Car Compound Interest Calculation:".$objCar->calculate(); 

echo "||";

//House class calculation
$objHouse = new House(10000, 10.25,5);
echo "House Compound Interest Calculation:".$objHouse->calculate(); 
?>

 

Categories: PHP Tags: #PHP OOPS,

Newsletter Subcribe

Receive updates and latest news direct from our team. Simply enter your email.