| 1 | <?php |
||
| 5 | class Candidate |
||
| 6 | { |
||
| 7 | const ELECTED = 1; |
||
| 8 | const RUNNING = 2; |
||
| 9 | const DEFEATED = 3; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Identifier for the candidate. |
||
| 13 | * |
||
| 14 | * @var int |
||
| 15 | */ |
||
| 16 | protected $id; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Number of votes the candidate currently has. |
||
| 20 | * |
||
| 21 | * @var float |
||
| 22 | */ |
||
| 23 | protected $votes; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * State of the candidate (use class constants). |
||
| 27 | * |
||
| 28 | * @var int |
||
| 29 | */ |
||
| 30 | protected $state; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Constructor. |
||
| 34 | */ |
||
| 35 | 5 | public function __construct(int $id) |
|
| 36 | { |
||
| 37 | 5 | $this->id = $id; |
|
| 38 | 5 | $this->votes = 0.0; |
|
| 39 | 5 | $this->state = self::RUNNING; |
|
| 40 | 5 | } |
|
| 41 | |||
| 42 | /** |
||
| 43 | * Gets the Identifier for the candidate. |
||
| 44 | * |
||
| 45 | * @return int |
||
| 46 | */ |
||
| 47 | 1 | public function getId(): int |
|
| 51 | |||
| 52 | /** |
||
| 53 | * Gets the Number of votes the candidate currently has. |
||
| 54 | * |
||
| 55 | * @return float |
||
| 56 | */ |
||
| 57 | 2 | public function getVotes(): float |
|
| 61 | |||
| 62 | /** |
||
| 63 | * Adds votes to a candidate. |
||
| 64 | * |
||
| 65 | * @param float $votes Number of votes to add |
||
| 66 | * |
||
| 67 | * @return self |
||
| 68 | */ |
||
| 69 | 1 | public function addVotes(float $votes) |
|
| 70 | { |
||
| 71 | 1 | $this->votes += $votes; |
|
| 72 | |||
| 73 | 1 | return $this; |
|
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Gets the State of the candidate (use class constants). |
||
| 78 | * |
||
| 79 | * @return int |
||
| 80 | */ |
||
| 81 | 3 | public function getState(): int |
|
| 85 | |||
| 86 | /** |
||
| 87 | * Sets the State of the candidate (use class constants). |
||
| 88 | * |
||
| 89 | * @param int $state the state |
||
| 90 | * |
||
| 91 | * @return self |
||
| 92 | */ |
||
| 93 | 1 | public function setState(int $state) |
|
| 99 | } |
||
| 100 |