本文整理汇总了PHP中Car::changeGear方法的典型用法代码示例。如果您正苦于以下问题:PHP Car::changeGear方法的具体用法?PHP Car::changeGear怎么用?PHP Car::changeGear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Car
的用法示例。
在下文中一共展示了Car::changeGear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
示例2: Person
<?php
require_once 'autoload.php';
$owner1 = new Person('Ivan', 19);
$peugeot = new Car('Peugeot', '2011', 'black', 5, 180, $owner1);
$peugeot->setCurrentGear('2');
$peugeot->setCurrentSpeed('32');
//var_dump($peugeot);
$peugeot->changeGear(8);
$peugeot->changeSpeed(100);
$peugeot->changeSpeed(190);
//var_dump($peugeot);
$owner2 = new Person('Dragan', 29);
$audi = new Car('Audi', '2012', 'green', 6, 230, $owner2);
$audi->setCurrentGear('3');
$audi->setCurrentSpeed('65');
//var_dump($audi);
$audi->changeGear(8);
$audi->changeGear(4);
$audi->changeSpeed(150);
$audi->changeSpeed(250);
/*var_dump($audi);
var_dump($owner1->getAge().' '. $owner1->getName());
var_dump($audi->display());
var_dump($peugeot->display());*/
$audi->changeGearDown();
$audi->changeGearUp();
$audi->changeGearUp();
$audi->changeGearUp();
$audi->changeGearUp();