From 974b7395d0cb252f1063bd74c7fcf92c7606f76a Mon Sep 17 00:00:00 2001 From: Marian Roibu Date: Mon, 30 Jan 2023 18:08:39 +0100 Subject: [PATCH] completed --- Form.php | 32 ++++++++++++++++++++++++++++ Interface.php | 9 ++++++++ README.md | 13 +++++++++++ Road_legal.php | 41 +++++++++++++++++++++++++++++++++++ Vehicle.php | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 153 insertions(+) create mode 100644 Form.php create mode 100644 Interface.php create mode 100644 Road_legal.php create mode 100644 Vehicle.php diff --git a/Form.php b/Form.php new file mode 100644 index 0000000..0130477 --- /dev/null +++ b/Form.php @@ -0,0 +1,32 @@ +radius = $radius; + } + + public function getRadius() { + return $this->radius; + } + + public function setRadius($radius) { + $this->radius = $radius; + } + + public function getArea() { + return pi() * pow($this->radius, 2); + } + + public function getPerimeter() { + return 2 * pi() * $this->radius; + } +} + +$circle = new Circle(5); +echo "Circle Area:
" . $circle->getArea(), '
'; +echo "Circle Perimeter:
" . $circle->getPerimeter(), '
'; + +?> \ No newline at end of file diff --git a/Interface.php b/Interface.php new file mode 100644 index 0000000..6b62e90 --- /dev/null +++ b/Interface.php @@ -0,0 +1,9 @@ + diff --git a/README.md b/README.md index e644e6a..30ad2d9 100644 --- a/README.md +++ b/README.md @@ -134,3 +134,16 @@ Namespaces are qualifiers that solve two different problems: 2. They allow the same name to be used for more than one class In this file you will learn how to create and use namespaces. + +### [Namespaces](Vehicle.php) +Main file that creates and destructs the data + +### [Namespaces](Road_legal.php) +Secondary file that rewrites the main data + + +### [Namespaces](Form.php) +Main file that constructs the data using an abstract class + +### [Namespaces](Interface.php) +Secondary file that uses the data from the main file "Form" \ No newline at end of file diff --git a/Road_legal.php b/Road_legal.php new file mode 100644 index 0000000..3ef5219 --- /dev/null +++ b/Road_legal.php @@ -0,0 +1,41 @@ +activeAero = $activeAero; + self::$numOfCars++; + } + + public function getActiveAero() { + return $this->activeAero; + } + + public function setActiveAero($activeAero) { + $this->activeAero = $activeAero; + } + + public function startAero() { + return "The active aerodinamic is working.
"; + } + + public static function getNumOfCars() { + return self::$numOfCars; + } +} + +$electricCar = new RoadLeagal('Pagani', 'Huayra', 2011, 'Active'); +echo $electricCar->getMake(), '
'; +echo $electricCar->getModel(), '
'; +echo $electricCar->getYear(), '
'; +echo $electricCar->getActiveAero(), '
'; +echo RoadLeagal::getNumOfCars(), '

'; + + + +?> \ No newline at end of file diff --git a/Vehicle.php b/Vehicle.php new file mode 100644 index 0000000..4fb5b9f --- /dev/null +++ b/Vehicle.php @@ -0,0 +1,58 @@ +make = $make; + $this->model = $model; + $this->year = $year; + } + + public function __destruct() { + echo "The vehicle has been destroyed.
"; + } + + public function getMake() { + return $this->make; + } + + public function getModel() { + return $this->model; + } + + public function getYear() { + return $this->year; + } + + public function startEngine() { + return "The engine is running.
"; + } + + public function stopEngine() { + return "The engine is off.
"; + } + +} + +class Car extends Vehicle { + private $doors; + + public function __construct($make, $model, $year, $doors) { + parent::__construct($make, $model, $year); + $this->doors = $doors; + } + + public function getDoors() { + return $this->doors; + } +} + +$car = new Car('Pagani', 'Zonda R', 1999, 2); +echo $car->getMake(), '
'; +echo $car->getModel(), '
'; +echo $car->getYear(), '
'; +echo $car->getDoors(), '

'; + +?> \ No newline at end of file