Completing this exam will demonstrate comprehension of most of the principles of Object Oriented Programming.
public function revDown($footPressure)
{
}
}
class Wheel { private $speed; private $distance;
public function spinForward($forceApplied)
{
// Set the traveling speed.
}
public function spinBackward($forceApplied)
{
// Set the traveling speed (negative for reverse).
}
public function getSpeed() { }
public function distanceTraveled() { }
}
class GasTank { private $tankSize; private $fuel;
public function __construct($tankSize) { }
public function refuel() { }
public function getFuelRemaining() { }
}
class HondaInsightCar { // Make constants called DRIVE_FORWARD and DRIVE_REVERSE
private $engine;
private $wheels;
private $gasTank;
public function __construct()
{
// Add a gas tank.
$this->gasTank = new GasTank(10.0);
// Add an engine.
// Add four Wheels to $this->wheels using a for loop.
}
// Right now our car will only be able to drive in a straight line
// either forward or in reverse.
public function drive($footPressure, $minutesToDrive, $direction = self::FORWARD)
{
// Use a loop
$this->engine->revUp($footPressure);
}
public function brake($footPressure)
{
$this->engine->revDown($footPressure);
}
public function refuel() { }
public function calculateMileage() { }
public function calculateFuelEfficiency() { }
}
= Measure of Success =
On successful completion, the following code will work:
You may want to copy code from [[PHPBook:Real_Property_Encapsulation#Example_of_Real_Property_Encapsulation|Example of Real Property Encapsulation]].
My implementation can be found at http://repo.phpexperts.pro/source/driving_app/annotate/head:/index.php
[[Category:PHP_From_Beginner_to_Pro]]