Question: Write a declaration for Car class, using the variable names and method names mentioned below. Leave the bodies of the methods empty. For programming purposes,
Write a declaration for Car class, using the variable names and method names mentioned below. Leave the bodies of the methods empty.
For programming purposes, we can focus on just a few elements of the state:
Is the engine on?
How much fuel remains in the car's tank?
Instance methods for cars:
startEngine: Stores true into engineIsOn.
stopEngine: Stores false into engineIsOn.
drive: Reduces fuelRemaining by an amount calculated by dividing the distance traveled by the expected fuel consumption.
addFuel: Increase fuelRemaining by a specified amount.
Then write statements that perform the following operations on car.
a. starts car's engine
b. Drive car for 120 miles
c. Add 9.2 gallons to car's tank
d. Stop car's engine
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
