Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. <?php
  2.  
  3. class Transport{
  4. protected $model;
  5. protected $speed;
  6.  
  7. function __construct($model, $speed){
  8. $this->model = $model;
  9. $this->speed = $speed;
  10. }
  11.  
  12. protected function setSpeed($newSpeed){
  13. $this->speed = $newSpeed;
  14. }
  15.  
  16. protected function getSpeed(){
  17. return $this->speed;
  18. }
  19.  
  20. protected function getModel(){
  21. return $this->speed;
  22. }
  23.  
  24. }
  25.  
  26. class Car extends Transport{
  27. private $fuelType;
  28.  
  29. function __construct($model, $speed, $fuelType){
  30. parent::__construct($model, $speed);
  31. $this->fuelType = $fuelType;
  32. }
  33.  
  34. public function getFuelType(){
  35. return $this->fuelType;
  36. }
  37.  
  38. public function printInfo(){
  39. echo __CLASS__ . ":<br>"
  40. . "Model: " . $this->model . "<br>"
  41. . "Speed: " . $this->speed . "<br>"
  42. . "FuelType: " . $this->fuelType . "<br>"
  43. . "<hr>";
  44. }
  45.  
  46. }
  47.  
  48. class Plane extends Transport{
  49. private $wingSpan;
  50.  
  51. public function __construct($model, $speed, $wingSpan){
  52. parent::__construct($model, $speed);
  53. $this->wingSpan = $wingSpan;
  54. }
  55.  
  56. public function setWingSpan($newWingSpan){
  57. $this->wingSpan = $newWingSpan;
  58. }
  59.  
  60. public function getWingSpan(){
  61. return $this->wingSpan;
  62. }
  63.  
  64. public function printInfo(){
  65. echo __CLASS__ . ":<br>"
  66. . "Model: " . $this->model . "<br>"
  67. . "Speed: " . $this->speed . "<br>"
  68. . "WingSpan: " . $this->wingSpan . "<br>"
  69. . "<hr>";
  70. }
  71.  
  72. }
  73.  
  74. echo "<br><h2>Cars</h2><br>";
  75.  
  76. $car1 = new Car("Lada", 30, "disel");
  77. $car2 = new Car("Opel", 10, "benzin");
  78. $car3 = new Car("Bulgareno", 50, "rakia");
  79. $car1->printInfo();
  80. $car2->printInfo();
  81. $car3->printInfo();
  82.  
  83. echo "<br><h2>Planes</h2><br>";
  84.  
  85. $plane1 = new Plane("Boing", 200, 50);
  86. $plane2 = new Plane("Airbus", 50, 70);
  87. $plane3 = new Plane("Mig", 1000, 20);
  88. $plane1->printInfo();
  89. $plane2->printInfo();
  90. $plane3->printInfo();
  91. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement