Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Car
- {
- private $mark;
- private $power;
- private $model;
- private $color;
- private $visits = [];
- private $distance;
- public function __construct($mark, $power, $model, $color, $distance)
- {
- $this->mark = $mark;
- $this->power = $power;
- $this->model = $model;
- $this->color = $color;
- $this->distance = $distance;
- }
- public function addVisit($visit)
- {
- $this->visits[] = $visit;
- }
- public function getVisitsInfo()
- {
- for ($i = 0; $i < count($this->visits); $i++) {
- $tmp = $i + 1;
- echo "Wizyta: $tmp o dacie: {$this->visits[$i]}";
- }
- }
- public function getInfo()
- {
- 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);
- }
- }
- $fiat = new Car('Fiat', 382, 'Punto', 'Gray', 350000);
- $fiat->addVisit('28-12-2016');
- $fiat->addVisit('25-12-2016');
- $fiat->addVisit('11-12-2016 - Wymiana silnika');
- $fiat->getVisitsInfo();
- echo '<br>';
- echo $fiat->getInfo();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement