Witam, mam nastepujace zadanie do wykonania:
Napisać klase Car oraz nastepujace funkcje:
$car1 = new Car("Samochod 1");
$car2 = new Car("Samochod 1");
$car1 ->setColor("zielony");
$car2 ->setColor("czerwony");
$car1->setLength(5.0)
$car1->setLength(1.6);
$car1->setLength(2.0);
$car1->setType("Sport");
$car2->setTpe("city");
$car1->getInfo();
$car2->getInfo();
WYNIK:
Samochod 1:
-kolor zielony
-Wymiar: 5.0 x 1.6 x 2.0
-Typ: sportowy
to samo do drugiego
Zrobilem cos takiego ale w dalszym ciagu nie dziala mi w funkcji getInfo() wypisywanie wymiarow pojazdu. Prosze o pomoc.
<?php class Car { public $color; public $length = array(); public $type; private $name; function __construct($name){ $this->name = $name; } public function setColor($color){ $this->color = $color; return true; } public function setLength($length){ $this->$length[] = $length; return true; } public function setType($type){ $this->type = $type; return true; } public function getInfo(){ echo $this->name.''; echo '- kolor '.$this->color.'
'; echo '- wymiary:'.$this->length[0]. ' x ' .$this->length[1].' x '.$this->length[2].'
'; echo '-Typ: '.$this->type.'
'; return true; } } $car1 = new Car("Samochod 1"); $car2 = new Car("Samochod 2"); $car1->setColor("zielony"); $car2->setColor("czerwony"); $car1->setLength(5.0); $car1->setLength(1.6); $car1->setLength(2.0); $car1->setType("Sport"); $car2->setType("city"); $car1->getInfo(); $car2->getInfo(); ?>