-
Notifications
You must be signed in to change notification settings - Fork 0
/
Car.php
82 lines (67 loc) · 1.51 KB
/
Car.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* Class car
*/
class Car
{
//Properties
private int $nbWheels;
private int $currentSpeed;
private string $color;
private int $nbSeats;
private string $energy;
private int $energyLevel;
//Construct
public function __construct(string $color, int $nbSeats, string $energy)
{
// code...
$this->color = $color;
$this->nbSeats = $nbSeats;
$this->energy = $energy;
}
//Getters/Setters
public function getNbWheels(): int
{
return $this->nbWheels;
}
public function getCurrentSpeed(): int
{
return $this->currentSpeed;
}
public function getColor(): string
{
return $this->color;
}
public function getNbSeats(): int
{
return $this->nbSeats;
}
public function getEnergy(): string
{
return $this->energy;
}
public function getEnergyLevel(): int
{
return $this->energyLevel;
}
//Methods
public function start(): string
{
return 'Youpi, mon moteur est allumé. Nous allons pouvoir y aller.' . PHP_EOL;
}
public function forward(): string
{
$this->currentSpeed = rand(1, 100);
return 'Go driver !';
}
public function brake(): string
{
$sentence = '';
while ($this->currentSpeed > 0) {
$this->currentSpeed--;
$sentence .= 'Stop this car !' . PHP_EOL;
}
$sentence .= 'The car has stopped.';
return $sentence;
}
}