fursty

PHP

Apr 22nd, 2019
84
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <body>
  3. <?php
  4. abstract class Vehicle {
  5. private $manufacturer;
  6. private $model;
  7. private $number;
  8. private $maxSkorost;
  9. private $fuelPer100km;
  10.  
  11. public function __construct($manufacturer, $model, $number, $maxSkorost, $fuelPer100km) {
  12. $this->manufacturer=$manufacturer;
  13. $this->model=$model;
  14. $this->number=$number;
  15. $this->maxSkorost=$maxSkorost;
  16. $this->fuelPer100km=$fuelPer100km;
  17. }
  18.  
  19. public function getManufacturer(){
  20. return $this->manufacturer;
  21. }
  22.  
  23. public function getModel(){
  24. return $this->model;
  25. }
  26.  
  27. public function getNumber(){
  28. return $this->number;
  29. }
  30.  
  31. public function getmaxSkorost(){
  32. return $this->maxSkorost;
  33. }
  34.  
  35. public function getFuelPer100km(){
  36. return $this->fuelPer100km;
  37. }
  38.  
  39. public function setNumber($number){
  40. $this->number=$number;
  41. }
  42.  
  43. public function setMaxSpeed($speed){
  44. $this->maxSkorost=$speed;
  45. }
  46.  
  47. public function saveToFile()
  48. {
  49. $myfile = fopen("record.txt", "a") or die("Unable to open file!");
  50. $text = "Manufacturer: $this->manufacturer, Model: $this->model, Number: $this->number, Max speed: $this->maxSkorost, Fuel/100: $this->fuelPer100km";
  51. fwrite($myfile, "\n".$text);
  52. fclose($myfile);
  53. }
  54. }
  55. class Car extends Vehicle{
  56. private $doorsCount;
  57.  
  58. public function __construct($manufacturer, $model, $number, $maxSkorost, $fuelPer100km, $doorsCount) {
  59. parent::__construct($manufacturer, $model, $number, $maxSkorost, $fuelPer100km);
  60. $this->doorsCount=$doorsCount;
  61. }
  62.  
  63. public function getDoorsCount(){
  64. return $this->doorsCount;
  65. }
  66. }
  67. class Bus extends Vehicle {
  68. private $seatsCount;
  69. private $wheelsCount;
  70.  
  71. public function __construct($manufacturer, $model, $number,$maxSkorost, $fuelPer100km, $seatsCount, $wheelsCount) {
  72. parent::__construct($manufacturer, $model, $number, $maxSkorost, $fuelPer100km);
  73. $this->seatsCount=$seatsCount;
  74. $this->wheelsCount=$wheelsCount;
  75. }
  76.  
  77. public function getSeatsCount(){
  78. return $this->seatsCount;
  79. }
  80.  
  81. public function getWheelsCount(){
  82. return $this->wheelsCount;
  83. }
  84. }
  85. class SchoolBus extends Bus{
  86. private $schoolName;
  87.  
  88. public function __construct($manufacturer, $model, $number, $maxSkorost, $fuelPer100km, $seatsCount, $wheelsCount, $schoolName) {
  89. parent::__construct($manufacturer, $model, $number, $maxSkorost, $fuelPer100km, $seatsCount, $wheelsCount);
  90. $this->$schoolName=$schoolName;
  91. }
  92.  
  93. public function getSchoolName()
  94. {
  95. return $this->schoolName;
  96. }
  97.  
  98. public function setSchoolName($name)
  99. {
  100. $this->schoolName=$name;
  101. }
  102. }
  103. $myCar = new Car("carProizvoditel","carModel",300,10,111,4);
  104. echo $myCar->getManufacturer() . "<br/>";
  105. echo $myCar->getModel() . "<br/>";
  106. echo $myCar->getMaxSkorost() . "<br/>";
  107. echo $myCar->getFuelPer100km() . "<br/>";
  108. echo $myCar->getNumber() . "<br/>";
  109. echo $myCar->getDoorsCount() . "<br/>";
  110.  
  111. echo "<br/><br/>";
  112. $myBus = new Bus("BusProizvoditel","busModel",200,20,222,30,4);
  113. echo $myBus->getManufacturer() . "<br/>";
  114. echo $myBus->getModel() . "<br/>";
  115. echo $myBus->getMaxSkorost() . "<br/>";
  116. echo $myBus->getFuelPer100km() . "<br/>";
  117. echo $myBus->getNumber() . "<br/>";
  118. echo $myBus->getSeatsCount() . "<br/>";
  119. echo $myBus->getWheelsCount() . "<br/>";
  120.  
  121. echo "<br/><br/>";
  122. $mySchoolBus = new SchoolBus("SchoolBusProizvoditel","schoolBusModel",100,30,111,30,4,"Uni");
  123. echo $mySchoolBus->getManufacturer() . "<br/>";
  124. echo $mySchoolBus->getmodel() . "<br/>";
  125. echo $mySchoolBus->getMaxSkorost() . "<br/>";
  126. echo $mySchoolBus->getFuelPer100km() . "<br/>";
  127. echo $mySchoolBus->getNumber() . "<br/>";
  128. echo $mySchoolBus->getSeatsCount() . "<br/>";
  129. echo $mySchoolBus->getWheelsCount() . "<br/>";
  130. echo $mySchoolBus->getSchoolname() . "<br/>";
  131.  
  132. $myCar->saveToFile();
  133.  
  134.  
  135. ?>
  136.  
  137. </body>
  138. </html>
RAW Paste Data