/
bike.php
54 lines (43 loc) · 1.12 KB
/
bike.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
<?php
class Bike {
public $price;
public $max_speed;
public $miles;
public function __construct($price_val, $max_speed_val) {
echo "You made a new bike!<br>";
$this->price = $price_val;
$this->max_speed = $max_speed_val;
$this->miles = 0;
}
public function displayInfo() {
echo "<u>INFO</u><br>";
echo "-Price: $".$this->price.'<br>';
echo "-Max Speed: ".$this->max_speed.' mph<br>';
echo "-Miles: ".$this->miles.' mi<br>';
return $this;
}
public function drive() {
echo "*You drive 10 miles across the screen!*<br>";
$this->miles += 10;
return $this;
}
public function reverse() {
echo "*You back up 5 miles across the screen!*<br>";
$this->miles -= 5;
if($this->miles < 0) {
$this->miles = 0;
echo "~OOPS! You backed up too far and hit the wall!~<br>";
}
return $this;
}
}
$bike1 = new Bike(600, 60);
$bike1->drive()->drive()->drive()->reverse()->displayInfo();
echo "<br>";
$bike2 = new Bike(300, 30);
$bike2->drive()->drive()->reverse()->reverse()->displayInfo();
echo "<br>";
$bike3 = new Bike(100, 15);
$bike3->reverse()->reverse()->reverse()->displayInfo();
echo "<br>";
?>