-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarro.php
More file actions
30 lines (25 loc) · 802 Bytes
/
Carro.php
File metadata and controls
30 lines (25 loc) · 802 Bytes
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
<?php
class Carro {
//Atributos
public int $capacidade;
public int $kilometragem;
public float $combustivel = 0;
function __construct( $capacidade, $kilometragem ) {
$this->capacidade = $capacidade;
$this->kilometragem = $kilometragem;
echo 'Kilometragem:' .$this->kilometragem.' Combustivel:'.$this->combustivel.'<br>';
}
function andar($km) {
$this->kilometragem += $km;
$this->combustivel -= 0.1*$km;
return 'Kilometragem:' .$this->kilometragem.' Combustivel:'.$this->combustivel.'<br>';
}
function abastecer($litros){
if (($this->combustivel + $litros) > $this->capacidade) {
$this->combustivel = $this->capacidade;
} else {
$this->combustivel += $litros;
}
}
}
?>