-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransport_management.php
49 lines (38 loc) · 1.2 KB
/
transport_management.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
42
43
44
45
46
47
48
49
<?php
abstract class Transport {
protected $idTrans;
protected $speed;
protected $capacity;
public function __construct($idTrans, $speed, $capacity) {
$this->idTrans = $idTrans;
$this->speed = $speed;
$this->capacity = $capacity;
}
public function infos() {
echo "ID: " . $this->idTrans . "<br>";
echo "Speed: " . $this->speed . " km/h<br>";
echo "Capacity: " . $this->capacity . " passengers<br>";
}
abstract public function amount();
}
class Autocar extends Transport {
private $brand;
private $ticketPrice;
public function __construct($idTrans, $speed, $capacity, $brand, $ticketPrice) {
parent::__construct($idTrans, $speed, $capacity);
$this->brand = $brand;
$this->ticketPrice = $ticketPrice;
}
public function infos() {
parent::infos();
echo "Brand: " . $this->brand . "<br>";
echo "Ticket Price:" . $this->ticketPrice . " MAD <br>";
}
public function amount() {
return $this->capacity * $this->ticketPrice;
}
}
$a1 = new Autocar(1, 90, 70, "Hyundai", 200);
$a1->infos();
echo "Total Amount if all tickets are sold: " . $a1->amount() . " MAD";
?>