Advertisement
sanjiisan

Untitled

Apr 10th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. <?php
  2.  
  3. class Car
  4. {
  5. private $mark;
  6. private $power;
  7. private $model;
  8. private $color;
  9. private $visits = [];
  10.  
  11. private $distance;
  12.  
  13. public function __construct($mark, $power, $model, $color, $distance)
  14. {
  15. $this->mark = $mark;
  16. $this->power = $power;
  17. $this->model = $model;
  18. $this->color = $color;
  19. $this->distance = $distance;
  20. }
  21.  
  22. public function addVisit($visit)
  23. {
  24. $this->visits[] = $visit;
  25. }
  26.  
  27. public function getVisitsInfo()
  28. {
  29. for ($i = 0; $i < count($this->visits); $i++) {
  30. $tmp = $i + 1;
  31. echo "Wizyta: $tmp o dacie: {$this->visits[$i]}";
  32. }
  33. }
  34.  
  35. public function getInfo()
  36. {
  37. return "Samochód marki: {$this->mark} model: {$this->model} o mocy: {$this->power} i kolorze: {$this->color}. Ilość Januszy mechaników o których był samochód to: " . count($this->visits);
  38. }
  39. }
  40.  
  41. $fiat = new Car('Fiat', 382, 'Punto', 'Gray', 350000);
  42.  
  43. $fiat->addVisit('28-12-2016');
  44. $fiat->addVisit('25-12-2016');
  45. $fiat->addVisit('11-12-2016 - Wymiana silnika');
  46.  
  47. $fiat->getVisitsInfo();
  48.  
  49. echo '<br>';
  50.  
  51.  
  52. echo $fiat->getInfo();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement