@@ -0,0 +1,1910 @@
+// Build a sub class of Vehicle of trucks.%0Aclass Vehicle %7B%0A%09private int passengers; // number of passengers%0A%09private int fuelcap;    // fuel capacity in gallons%0A%09private int mpg;        // fuel consumption in miles per gallon%0A%09%0A%09// This is a constructor for Vehicle.%0A%09Vehicle(int p, int f, int m) %7B%0A%09%09passengers = p;%0A%09%09fuelcap = f;%0A%09%09mpg = m;%0A%09%7D%0A%09%0A%09// Return the range.%0A%09int range() %7B%0A%09%09return mpg * fuelcap;%0A%09%7D%0A%09%0A%09// Compute fuel needed for a given distance.%0A%09double fuelneeded(int miles) %7B%0A%09%09return (double) miles / mpg;%0A%09%7D%0A%09%0A%09// Access methods for instance variables.%0A%09int getPassengers() %7B return passengers; %7D%0A%09void setPassengers(int p) %7B passengers = p; %7D%0A%09int getFuelcap() %7B return fuelcap; %7D%0A%09void setFuelcap(int f) %7B fuelcap = f; %7D%0A%09int getMpg() %7B return mpg; %7D%0A%09void setMpg(int m) %7B mpg = m; %7D%0A%7D%0A%0A// Extend Vehicle to create a Truck specialization.%0Aclass Truck extends Vehicle %7B%0A  private int cargocap; // cargo capacity in pounds%0A  %0A  // This is a constructor for Truck.%0A  Truck(int p, int f, int m, int c) %7B%0A    /*%0A      Initialize Vehicle members using Vehicle's constructor.%0A    */%0A    super(p, f, m);%0A    %0A    cargocap = c;%0A  %7D%0A  %0A  // Accessor methods for cargocap.%0A  int getCargo() %7B return cargocap; %7D%0A  void putCargo(int c) %7B cargocap = c; %7D%0A%7D%0A%0Aclass TruckDemo %7B%0A%09public static void main(String args%5B%5D) %7B%0A%09%09%0A%09%09// construct some trucks%0A%09%09Truck semi = new Truck(2, 200, 7, 44000);%0A%09%09Truck pickup = new Truck(3, 28, 15, 2000);%0A%09%09double gallons;%0A%09%09int dist = 252;%0A%09%09%0A%09%09gallons = semi.fuelneeded(dist);%0A%09%09%0A%09%09System.out.println(%22Semi can carry %22 + semi.getCargo() + %22 pounds.%22);%0A%09%09System.out.println(%22To go %22 + dist + %22 miles semi needs %22 + gallons + %22 gallons of fuel.%5Cn%22);%0A%09%09%0A%09%09gallons = pickup.fuelneeded(dist);%0A%09%09%0A%09%09System.out.println(%22Pickup can carry %22 + pickup.getCargo() + %22 pounds.%22);%0A%09%09System.out.println(%22To go %22 + dist + %22 miles pickup needs %22 + gallons + %22 gallons of fuel.%5Cn%22);%0A%09%7D%0A%7D%0A

Build a sub class of Vehicle of trucks