Esempio n. 1
0
        echo "Reversing...";
        $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();
Esempio n. 2
0
        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>";
Esempio n. 3
0
    {
        $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();