本文整理汇总了PHP中Car::accelerate方法的典型用法代码示例。如果您正苦于以下问题:PHP Car::accelerate方法的具体用法?PHP Car::accelerate怎么用?PHP Car::accelerate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Car
的用法示例。
在下文中一共展示了Car::accelerate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testMaxSpeed
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());
}
示例2: Car
<?php
require_once 'autoload.php';
$car1 = new Car('BMW', true, 'black', 340000, 250);
$car1->setCurrentSpeed(100);
$car1->setCurrentGear(4);
$car2 = new Car('Audi', false, 'grey', 280000, 260);
$car2->setCurrentSpeed(150);
$car2->setCurrentGear(5);
echo "Gear is: ", $car1->getCurrentGear(), " and the speed is: ", $car1->getCurrentSpeed(), PHP_EOL;
$car1->changeGear(5);
$car1->accelerate();
echo "Now the gear is: ", $car1->getCurrentGear(), " and the speed is: ", $car1->getCurrentSpeed(), PHP_EOL;
$shop = new CarShop();
$shop->addCar($car1);
$shop->addCar($car2);
$shop->showAllCarsInTheShop();
示例3: Car
<?php
require 'autoload.php';
$ferrari = new Car('Ferrari', 400, 0, 'red', 0);
$bmw = new Car('bmw', 320, 0, 'blue', 0);
echo $ferrari->display();
$ferrari->setCurrentGear(3);
$ferrari->setCurrentSpeed(60);
echo $ferrari->display();
$somebody = new Person("Ivan", 36);
$ferrari->setOwner($somebody);
echo $ferrari->getOwner();
$ferrari->accelerate(200);
echo "<br>";
echo $ferrari->getCurrentSpeed();
echo "<br>";
$ferrari->changeGearUp();
echo $ferrari->getCurrentGear();
//$ferrari->accelerate(300);
//echo $ferrari->getCurrentSpeed();
示例4: Car
$merc = new Car("Voldemor", "mercedez-benz", "220", "silver", false);
echo "<h3>Car 2 (merc) properties: " . $merc->getColor() . "</h3>";
echo "<p>" . $merc->getModel() . "</p>";
echo "<p>" . $merc->getMaxspeed() . "</p>";
echo "<p>" . $merc->getcurrentSpeed() . "</p>";
echo "<p>" . $merc->getColor() . "</p>";
echo "<p>" . $merc->getCurrentGear() . "</p>";
//Show old speed
echo "<p> Old Speed: " . $merc->getcurrentSpeed() . " </p>";
//Change the speed
$merc->setcurrentSpeed(60);
//Show new speed
echo "<p>Changed Speed: </p>";
echo "<p>" . $merc->getcurrentSpeed() . "</p>";
//Accelerate
echo "<p>Accelerated speed : " . $merc->accelerate() . "</p> ";
//Show old gear
echo "<p> Old Gear: " . $merc->getcurrentGear() . " </p>";
//Change the gear
$merc->setCurrentgear(4);
echo "<p>Changed Gear: </p>";
//Show new gear
echo "<p>" . $merc->getCurrentgear() . "</p>";
//Gear Up
echo "<p> GearUp:" . $merc->changeGearUp() . "</p>";
//Gear Down
echo "<p> GearDown:" . $merc->changeGearDown() . "</p>";
//Change Color
$merc->changeColor("pink");
echo "<p> Changed color :" . $merc->getColor() . "</p>";
//Set owner
示例5: 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>