Example #1
0
 public function testMaxSpeed()
 {
     $car = new Car();
     for ($i = 0; $i < 10; $i++) {
         $car->accelerate();
     }
     $this->assertEquals(100, $car->getSpeed());
     $car->accelerate();
     $this->assertEquals(100, $car->getSpeed());
 }
    {
        if ($this->_speed <= 0) {
            return false;
        }
        $this->_speed -= 10;
        return true;
    }
    public function getSpeed()
    {
        return $this->_speed;
    }
}
$myCar = new Car();
$myCar->color = "red";
$myCar->manufacturer = "Volkswagen";
$myCar->model = "Beetle";
echo "<p>I'm driving a {$myCar->color} {$myCar->manufacturer} {$myCar->model}.</p>";
echo "<p>Stepping on the gas...<br />";
while ($myCar->accelerate()) {
    echo "Current speed: " . $myCar->getSpeed() . " mph<br />";
}
echo "</p><p>Top speed! Slowing down...<br />";
while ($myCar->brake()) {
    echo "Current speed: " . $myCar->getSpeed() . " mph<br />";
}
echo "</p><p>Stopped!</p>";
?>

  </body>
</html>