PHP Write a Car class Write a class that models the concept of a Car that has a fuel economy (in miles per gallon), an odometer, and a gas tank. Your car should be able to drive a certain number of miles (specified as a parameter) until it reaches its distance or runs out of gas, whichever comes first. Further, you should write functionality to add gas to the car, and read the fuel gauge and the odometer. You should write the following methods: __construct($initialGas, $mpg): which takes the initial gas amount and miles per gallon as parameters. drive($miles): which will drive the specified miles (deducting gas from the tank and incrementing miles on the odometer) addGas($gallons): which will add more gas to the tank (the tank is of unlimited capacity). readFuelGauge(): which will return the number of gallons of gas remaining in the tank. readOdometer(): which will return the number of miles logged on the odometer.
PHP
Write a Car class
Write a class that models the concept of a Car that has a fuel economy (in miles per gallon), an odometer, and a gas tank. Your car should be able to drive a certain number of miles (specified as a parameter) until it reaches its distance or runs out of gas, whichever comes first. Further, you should write functionality to add gas to the car, and read the fuel gauge and the odometer. You should write the following methods:
-
__construct($initialGas, $mpg): which takes the initial gas amount and miles per gallon as parameters.
-
drive($miles): which will drive the specified miles (deducting gas from the tank and incrementing miles on the odometer)
-
addGas($gallons): which will add more gas to the tank (the tank is of unlimited capacity).
-
readFuelGauge(): which will return the number of gallons of gas remaining in the tank.
-
readOdometer(): which will return the number of miles logged on the odometer.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images