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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started