You could calculate the MPG of each car in the fleet and then average those numbers.
calculateMPG()
MethodFor us, there are two cars in the fleet, so the average MPG of the fleet will be the sum of the MPGs for each car, that sum divided by two. Here is the class, with more details:
It is perfectly OK for both Car
and Fleet
to have a
calculateMPG()
method.
Notice that when main()
uses calculateMPG()
it is clear which one to use:
the one that is part of the object referenced by myCars
(a Fleet
object).
Fill in the blanks for the calculateMPG()
method of Fleet
.