article

Sunday, August 25, 2013

Creating simple class php interest Calculator

Creating simple class php interest Calculator 

<?php
//Creating class interestCalculator
class interestCalculator
{
public $rate;
public $duration;
public $capital;
public function calculateInterest()
{
return ($this->rate*$this->duration*$this->capital)/100;
}
}
//Creating  various object of class interestCalculator to calculate interest on various amount
$cls1 = new interestCalculator();
$cls2 = new $cls1;
$cls1->rate =2;
$cls1->duration =3;
$cls1->capital = 300;

$cls2->capital = 400;

$interest1 = $cls1->calculateInterest();
$interest2  = $cls2->calculateInterest();
echo "$interest1 -- $interest2";

Related Post