Created
October 18, 2019 11:19
-
-
Save krez69/63afc0dfa04471d8cfac514d9796bdc2 to your computer and use it in GitHub Desktop.
Quete POO 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'Car.php'; | |
require_once 'Vehicle.php'; | |
require_once 'Truck.php'; | |
$Renault = new Truck('red','4','diesel',50); | |
$Renault->setLoadTest(60); | |
$Renault->setCurrentSpeed(3); | |
echo $Renault->getLoadTest(); | |
echo $Renault->brake(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Truck extends Vehicle | |
{ | |
/** | |
* @var integer | |
*/ | |
protected $capacity; | |
/** | |
* @var integer | |
*/ | |
protected $loadTest = 0; | |
public function __construct($color, $nbSeats, $energy, $capacity) | |
{ | |
parent::__construct($color, $nbSeats, $energy, $capacity); | |
$this->capacity = $capacity; | |
} | |
public function getCapacity(): int | |
{ | |
return $this->capacity; | |
} | |
public function setCapacity(int $capacity): void | |
{ | |
$this->capacity = $capacity; | |
} | |
public function getLoad(): int | |
{ | |
return $this->load; | |
} | |
public function setLoadTest(int $loadTest): void | |
{ | |
$this->loadTest = $loadTest; | |
} | |
public function getLoadTest(): string | |
{ | |
if($this->loadTest < $this->capacity){ | |
return 'in filling'; | |
}else{ | |
return 'full'; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Vehicle.php | |
class Vehicle | |
{ | |
/** | |
* @var string | |
*/ | |
protected $color; | |
/** | |
* @var integer | |
*/ | |
protected $currentSpeed; | |
/** | |
* @var integer | |
*/ | |
protected $nbSeats; | |
/** | |
* @var integer | |
*/ | |
protected $nbWheels; | |
public function __construct(string $color, int $nbSeats) | |
{ | |
$this->color = $color; | |
$this->nbSeats = $nbSeats; | |
} | |
public function forward(): string | |
{ | |
$this->currentSpeed = 15; | |
return "Go !"; | |
} | |
public function brake(): string | |
{ | |
$sentence = ""; | |
while ($this->currentSpeed > 0) { | |
$this->currentSpeed--; | |
$sentence .= "Brake !!!"; | |
} | |
$sentence .= "I'm stopped !"; | |
return $sentence; | |
} | |
public function getCurrentSpeed(): int | |
{ | |
return $this->currentSpeed; | |
} | |
public function setCurrentSpeed(int $currentSpeed): void | |
{ | |
if($currentSpeed >= 0){ | |
$this->currentSpeed = $currentSpeed; | |
} | |
} | |
public function getColor(): string | |
{ | |
return $this->color; | |
} | |
public function setColor(string $color): void | |
{ | |
$this->color = $color; | |
} | |
public function getNbSeats(): int | |
{ | |
return $this->nbSeats; | |
} | |
public function setNbSeats(int $nbSeats): void | |
{ | |
$this->nbSeats = $nbSeats; | |
} | |
public function getNbWheels(): int | |
{ | |
return $this->nbWheels; | |
} | |
public function setNbWheels(int $nbWheels): void | |
{ | |
$this->nbWheels = $nbWheels; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment