public class FlyingVehicle extends Vehicle // subclass which represents all flying vehicles (those that move through the air) { // this class of Vehicle will not be impacted by rough terrain protected boolean refuelInFlight; // can this vehicle refuel while flying? impacts distance protected boolean vtolCapable; // is this vehicle capable of vertical takeoffs/landings? impacts utility public FlyingVehicle() // no arg constructor { this("unknown"); } public FlyingVehicle(String t) // initialize all new instance data and override those of parent class that differ { super(t); refuelInFlight=false; vtolCapable=false; speed=200; armament=2; } // accessors for new instance data public boolean getVtol() { return vtolCapable; } public boolean getRefuel() { return refuelInFlight; } // compute the distance that this vehicle can travel - not part of the interface so is protected protected int getDistance() { if(refuelInFlight) return 10000; // if can refuel then distance is nearly unlimited else return speed*10; // otherwise distance is based on fuel } @Override public String toString() // add to parent toString output of new instance data { return super.toString() + " is VTOL capable " + vtolCapable + " can refuel in flight " + refuelInFlight; } // battle utility for flying vehicle based on whether the vehicle can travel the distance needed, if there is rough terrain to // avoid, if there is a need for ground support (troops) and if this vehicle can land to drop them off or not @Override public int getBattleUtility(boolean night, boolean roughTerrain, boolean needGroundSupport, boolean needHeavyArms, boolean antiAircraftGuns, boolean equipment, int distance) { int score=0; if(distance>getDistance()) score-=15; else score+=30; if(roughTerrain) score+=5; if(!needGroundSupport) score+=5; if(needGroundSupport&&vtolCapable&&capacity>2) score+=capacity; return score; } }