Advertisement
StessieFlt

POO

Oct 14th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.96 KB | None | 0 0
  1. Biycle.php
  2.  
  3. <?php
  4. class Bicycle
  5. {
  6.     private $color;
  7.     private $nbWheels = 2;
  8.     private $nbSeats = 1;
  9.     private $currentSpeed = 10;
  10.  
  11.     public function __contruct(string $color, int $nbSeats)
  12.     {
  13.         $this->color = $color;
  14.         $this->nbSeats = $nbSeats;
  15.     }
  16.  
  17.     public function setColor(string $color): string
  18.     {
  19.         $this->color= $color;
  20.         return $this;
  21.     }
  22.    
  23.     public function setnbSeats(string $nbSeats): int
  24.     {
  25.          $this->nbSeats = $nbSeats;
  26.          return $this;
  27.     }
  28.  
  29.     public function forward() : string
  30.     {
  31.         $this->currentSpeed = 15;
  32.         return "Go !";
  33.     }
  34.  
  35.     public function brake(): string
  36.     {
  37.         $sentence = "";
  38.         while ($this->currentSpeed > 0) {
  39.             $this->currentSpeed --;
  40.             $sentence .= "Brake !!!";
  41.         }
  42.         $sentence .= "I'm stopped !";
  43.         return $sentence;
  44.     }
  45.  
  46.     public function setCurrentSpeed(int $currentSpeed): int
  47.     {
  48.       if ($currentSpeed >= 0){
  49.           $this->currentSpeed = $currentSpeed;
  50.       }
  51.     }
  52.  
  53.     public function getCurrentSpeed() : int
  54.     {
  55.      return $this->currentSpeed;
  56.     }
  57.  
  58.     public function setnbWheels(string $nbWheels): string
  59.     {
  60.        $this->nbWheels = $nbWheels;
  61.        return $this;
  62.     }
  63.  
  64.     public function getnbWheels(): int
  65.     {
  66.       return $this->nbWheels;
  67.     }
  68. }
  69.  
  70.  
  71. Car.php
  72.  
  73. <?php
  74. class Car
  75. {
  76.     private $color;
  77.     private $nbWheels;
  78.     private $nbSeats;
  79.     private $currentSpeed = 30;
  80.  
  81.     public function __contruct(string $color, int $nbSeats)
  82.     {
  83.         $this->color = $color;
  84.         $this->nbSeats = $nbSeats;
  85.     }
  86.  
  87.     public function forward() : void
  88.     {
  89.         $this->currentSpeed > 0;
  90.         return "Go !";
  91.     }
  92.    
  93.     public function brake(): void
  94.     {
  95.         $sentence = "";
  96.         while ($this->currentSpeed > 0) {
  97.             $this->currentSpeed --;
  98.             $sentence .= "Brake !!!";
  99.         }
  100.         $sentence .= "I'm stopped !";
  101.         return $sentence;
  102.     }
  103.  
  104.     private function setColor(string $color): string
  105.     {
  106.         $this->color= $color;
  107.  
  108.         return $this;
  109.     }
  110.  
  111.     private function getColor() : string
  112.     {
  113.         return $this->color;
  114.     }
  115.  
  116.     public function setnbWheels(string $nbWheels) : string
  117.     {
  118.        $this->nbWheels = $nbWheels;
  119.        return $this;
  120.     }
  121.  
  122.     private function getnbWheels() : int
  123.     {
  124.         return $this->nbWheels;
  125.     }
  126.  
  127.     private function setnbSeats(string $nbSeats) : string
  128.     {
  129.         $this->nbSeats = $nbSeats;
  130.         return $this;
  131.     }
  132.  
  133.     private function getnbSeats() : int
  134.     {
  135.        return $this->nbseats;
  136.     }
  137.  
  138.     private function setCurrentSpeed(int $currentSpeed) : string
  139.     {
  140.       if ($currentSpeed >= 0){
  141.           $this->currentSpeed = $currentSpeed;
  142.       }
  143.     }
  144.  
  145.     private function getCurrentSpeed(): int
  146.     {
  147.      return $this->currentSpeed;
  148.     }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement