$this->miles = $this->miles - 5; if ($this->miles < 0) { //prevent the instance from having negative miles $this->miles = 0; } } } $bike1 = new Bike(200, "25mph"); //This instance drive 3x, reverse once and displayInfo() echo "<h3>Bike 1:</h3>"; $bike1->drive(); $bike1->drive(); $bike1->drive(); $bike1->reverse(); $bike1->displayInfo(); $bike2 = new Bike(300, "35mph"); //This instance drive 2x, reverse 2x, displayInfo() echo "<h3>Bike 2:</h3>"; $bike2->drive(); $bike2->drive(); $bike2->reverse(); $bike2->reverse(); $bike2->displayInfo(); $bike3 = new Bike(400, "45mph"); //This instance reverse 3x, displayInfo() echo "<h3>Bike 3:</h3>"; $bike3->reverse(); $bike3->reverse(); $bike3->reverse(); $bike3->displayInfo();
$this->price = $price; $this->max_speed = $max_speed; $this->miles = 0; } //methods public function displayInfo() { echo "hello\n"; echo "{$this->price} , {$this->max_speed}, {$this->miles}."; } public function get_displayInfo() { return $this->property1; } public function reverse() { echo "Reversing"; $this->miles = $miles - 5; } public function drive() { echo "Driving"; $this->miles = $miles + 10; } } $obj1 = new Bike(43, 21); // price and max speed. echo $obj1->drive(); echo $obj1->reverse(); echo $obj1->displayInfo();