We have chosen inheritance for code sharing across different implementations. The result looks as follows. Here is the VehicleImpl class:
abstract class VehicleImpl implements Vehicle { private int weightPounds, horsePower; public VehicleImpl(int weightPounds, int horsePower) { this.weightPounds = weightPounds; this.horsePower = horsePower; } protected int getWeightPounds(){ return this.weightPounds; } protected double getSpeedMph(double timeSec, int weightPounds){ double v = 2.0 * this.horsePower * 746 * timeSec * 32.174 / weightPounds; return Math.round(Math.sqrt(v) * 0.68); }}
Notice that some methods have protected access, meaning only members of the same package and class children can access them. That ...