Are actual car objects part of the definition of Fleet
?
No—the definition for Fleet
says that a Fleet
object has two variables that refer to Car
objects.
Fleet
The long-lasting state of a Fleet
object is held
in its two instance variables.
These variables refer to Car
objects.
The documentation for Fleet
might look like this:
FleetA class that holds two Car objects.
ConstructorsFleet( int Car1StartOdo, int Car1EndingOdo, double Car1Gallons, int Car2StartOdo, int Car2EndingOdo, double Car2Gallons )Creates a new instance of a Fleet object with the starting and ending odometer readings and the number of gallons of gas consumed for each car.
Methodsdouble calculateMPG()Calculates and returns the average miles per gallon for the fleet.
The constructor builds the two cars of the fleet.
SEach car needs three initial values.
So the constructor for Fleet
has a total
of six initial values.
(There are other more elegant ways to do this, but let us do it this way for now.)
Here is a short main()
that constructs a fleet:
class FleetTester
{
public static void main ( String[] args)
{
Fleet myCars = new Fleet( ____, ____, ____, ____, ____, ____ );
}
}