Prof. I. Rudowsky                                                                                   CIS 26MW12

Homework #8                                                                            Due Nov 22, 2004

Your are given the following classes – see picture below:

Vehicle has a String instance variable manufacturer.

Water has a integer instance variable displacement.

Land has a String instance variable numWheels.

Air has an instance variable numEngines.

Water,Land and Air each have a manufacturer that they get from inheritance or via an interface.

Amphibious has the characteristics of both a Land vehicle and Water vehicle.

 

This is the code in VehicleIntf:

public interface VehicleIntf {

 public String vehDesc();

}

 

The method vehDesc will return the values of all instance variables that are associated with that class along with the class name obtained via the getClass() method of Object. When vehDesc is invoked for an object of the class Amphibious, it will return the manufacturer, number of wheels and number displacement.

 

Write the code for each interface and the constructors and method vehDesc for each class. Then run the following driver class

 

public class VehicleDriver {

  public static void main(String[] args) {

    Vehicle[] v = new Vehicle[4];

    v[0] = new Land("Jaguar",4);

    v[1] = new Water("XYZ",1000);

    v[2] = new Air("Boeing",3);

    v[3] = new Amphibious("USNavy",3000,3);

   for (int i=0; i<v.length;i++){

     System.out.println(v[i].vehDesc());

   }

  }

}