Skip to content

Instantly share code, notes, and snippets.

@krez69
Created October 18, 2019 11:19
Show Gist options
  • Save krez69/63afc0dfa04471d8cfac514d9796bdc2 to your computer and use it in GitHub Desktop.
Save krez69/63afc0dfa04471d8cfac514d9796bdc2 to your computer and use it in GitHub Desktop.
Quete POO 2
<?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();
<?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';
}
}
}
<?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