Created
October 10, 2019 15:00
-
-
Save krez69/d3a1b0676f2c35a9898d11f5072b687e to your computer and use it in GitHub Desktop.
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 | |
// Bicycle.php | |
class Bicycle | |
{ | |
/** | |
* @var string | |
*/ | |
private $color; | |
/** | |
* @var integer | |
*/ | |
private $currentSpeed; | |
/** | |
* @var integer | |
*/ | |
private $nbSeats; | |
/** | |
* @var integer | |
*/ | |
private $nbWheels; | |
/*AVANCER*/ | |
public function forward() | |
{ | |
$this->currentSpeed = 15; | |
return "Go !"; | |
} | |
/*freiner*/ | |
public function brake(): string | |
{ | |
$sentence = ""; | |
while ($this->currentSpeed > 0) { | |
$this->currentSpeed--; | |
$sentence .= "Brake !!!"; | |
} | |
$sentence .= "I'm stopped !"; | |
return $sentence; | |
} | |
/** | |
* @return string | |
*/ | |
public function getColor(): string | |
{ | |
return $this->color; | |
} | |
/** | |
* @param string $color | |
*/ | |
public function setColor(string $color): void | |
{ | |
$this->color = $color; | |
} | |
/** | |
* @return int | |
*/ | |
public function getCurrentSpeed(): int | |
{ | |
return $this->currentSpeed; | |
} | |
/** | |
* @param int $currentSpeed | |
* @return void | |
*/ | |
public function setCurrentSpeed(int $currentSpeed): void | |
{ | |
if ($currentSpeed >= 0) { | |
$this->currentSpeed = $currentSpeed; | |
} | |
} | |
public function __construct(string $color) | |
{ | |
$this->color = $color; | |
} | |
} |
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 Car | |
{ | |
/** | |
* Le nom de roue | |
* @var Integer | |
*/ | |
private $nbWheels; | |
/** | |
* La vitesse courante | |
* @var Integer | |
*/ | |
private $currentSpeed; | |
/** | |
* La couleur | |
* @var String | |
*/ | |
private $color; | |
/** | |
* Le nombre de siege | |
* @var Integer | |
*/ | |
private $nbSeats; | |
/** | |
* L'énergie utilisée | |
* @var String | |
*/ | |
private $energy; | |
/** | |
* Le niveau de carburant/énergie actuel | |
* @var Integer | |
*/ | |
private $energyLevel; | |
/** | |
* @return INT | |
*/ | |
public function __construct(string $color, int $nbSeats, string $energy) | |
{ | |
$this->color = $color; | |
$this->nbSeats = $nbSeats; | |
$this->energy = $energy; | |
} | |
/*AVANCER*/ | |
public function forward() | |
{ | |
$this->currentSpeed = 15; | |
return "Go !"; | |
} | |
/*freiner*/ | |
public function brake(): string | |
{ | |
$sentence = ""; | |
while ($this->currentSpeed > 0) { | |
$this->currentSpeed--; | |
$sentence .= "Brake !!!"; | |
} | |
$sentence .= "I'm stopped !"; | |
return $sentence; | |
} | |
/*DEMARRER*/ | |
public function start() | |
{ | |
return "start !"; | |
} | |
/** | |
* @param String $nbWheel | |
* @return int | |
*/ | |
public function getNbWheels(): INT | |
{ | |
return $this->nbWheels; | |
} | |
public function setNbWheels(INT $nbWheel): Car | |
{ | |
$this->nbWheels = $nbWheel; | |
return $this; | |
} | |
/** | |
* @return int | |
*/ | |
public function getCurrentSpeed(): int | |
{ | |
return $this->currentSpeed; | |
} | |
/** | |
* @param int $currentSpeed | |
* @return void | |
*/ | |
public function setCurrentSpeed(int $currentSpeed): void | |
{ | |
if ($currentSpeed >= 0) { | |
$this->currentSpeed = $currentSpeed; | |
} | |
} | |
/** | |
* @return string | |
*/ | |
public function getColor(): string | |
{ | |
return $this->color; | |
} | |
/** | |
* @param string $color | |
*/ | |
public function setColor(string $color): void | |
{ | |
$this->color = $color; | |
} | |
/** | |
* @param String $nbSeats | |
* @return int | |
*/ | |
public function getNbSeats(): INT | |
{ | |
return $this->nbSeats; | |
} | |
public function setNbSeats(INT $nbSeats): Car | |
{ | |
$this->nbSeats = $nbSeats; | |
return $this; | |
} | |
/** | |
* @return string | |
*/ | |
public function getEnergy(): string | |
{ | |
return $this->energy; | |
} | |
/** | |
* @param string $energy | |
*/ | |
public function setEnergy(string $energy): string | |
{ | |
$this->energy = $energy; | |
return $this; | |
} | |
/** | |
* @param String $eneryLevel | |
* @return int | |
*/ | |
public function getEnergyLevel(): INT | |
{ | |
return $this->energyLevel; | |
} | |
public function setEnergyLevel(INT $energyLevel): Car | |
{ | |
$this->energyLevel = $energyLevel; | |
return $this; | |
} | |
} |
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 'Bicycle.php'; | |
require_once 'car.php'; | |
// Instanciation d'un nouvel objet $bike | |
$bike = new Bicycle('blue'); | |
$bike->setCurrentSpeed(20); | |
// Instanciation d'un nouvel objet $rockrider | |
$rockrider = new Bicycle('yellow'); | |
// Instanciation d'un nouvel objet $tornado | |
$tornado = new Bicycle('black'); | |
// Instanciation d'un nouvel objet $K2000 | |
$K2000 = new Car('black',2,'gazol'); | |
$K2000->setNbWheels(4); | |
$K2000->setCurrentSpeed(5); | |
// Instanciation d'un nouvel objet $carz | |
$carz = new Car('red',2,'essence'); | |
$carz->setNbWheels(4); | |
var_dump($bike); | |
var_dump($rockrider); | |
var_dump($tornado); | |
var_dump($K2000); | |
var_dump($carz); | |
echo $K2000->start(); | |
echo $bike->forward(); | |
echo $K2000->brake(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment