public class GroundVehicle extends Vehicle // Ground vehicle is a type of Vehicle that travels on the ground using tires or tread { // and so is impacted by terrain and also has a limited distance of travel protected boolean roughTerrainCapable; // can this type of ground vehcle make it over rough terrain? public GroundVehicle() // no arg constructor { this("unknown"); } public GroundVehicle(String t) { super(t); roughTerrainCapable=false; // establish values unique to GroundVehicle speed=50; armament=10; capacity=4; heavilyArmored=true; } protected int getDistance() // getDistance based on speed and how much fuel it consumes (based on heavily armored or not) { if(heavilyArmored) return speed*30; else return speed*45; } @Override // use parent toString and add roughTerrainCapable public String toString() { return super.toString() + " and is rough terrain capable " + roughTerrainCapable; } // getBattleUtility is specific to Ground Vehicle's strengths and weaknesses: cannot traverse rough terrain unless // rough terrain capable, and if ground support is needed, is useful if capacity is more than 1, cannot travel a great distance public int getBattleUtility(boolean night, boolean roughTerrain, boolean needGroundSupport, boolean needHeavyArms, boolean antiAircraftGuns, boolean equipment, int distance) { int score; if(roughTerrain&&!roughTerrainCapable) score=-5; else score=8; if(needGroundSupport)score+=capacity-1; if(distance>getDistance()) score=score-10; return score; } }