-
Notifications
You must be signed in to change notification settings - Fork 0
/
o4.php
42 lines (33 loc) · 1.18 KB
/
o4.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
class PetrolMileageCalculator{
public $pricePerLitre = 122;
public $distance;
public $totalFuelPrice;
public function __construct( $distance, $totalFuelPrice){
$this->distance = $distance;
$this->totalFuelPrice = $totalFuelPrice;
}
function calculateKMPL(){
$totalFuel = $this->totalFuelPrice / $this->pricePerLitre;
$mileage = $this->distance/$totalFuel;
echo "The mileage of the vehicle is {$mileage} kmpl and it runs on petrol.\n";
}
}
class OctaneMileageCalculator{
public $pricePerLitre = 130;
public $distance;
public $totalFuelPrice;
public function __construct( $distance, $totalFuelPrice){
$this->distance = $distance;
$this->totalFuelPrice = $totalFuelPrice;
}
function calculateKMPL(){
$totalFuel = $this->totalFuelPrice / $this->pricePerLitre;
$mileage = $this->distance/$totalFuel;
echo "The mileage of the vehicle is {$mileage} kmpl and it runs on octane.\n";
}
}
$car = new PetrolMileageCalculator(100, 2000); //instantiate
$car->calculateKMPL();
$motorcycle = new OctaneMileageCalculator(100, 300); //instantiate
$motorcycle->calculateKMPL();