public class TroopCarrier extends GroundVehicle // type of GroundVehicle primarily used to transport troops, but can also { // transport equipment, some are armed with heavier armaments, some are fast private boolean armed; // is armed or is not armed for fighting public TroopCarrier() // no arg constructor assumes normal troop carrier { this("Normal"); } public TroopCarrier(String t) // establish specific values unique to the types of troop carriers { super(t); roughTerrainCapable=true; // all are roughTerrainCapable and heavilyArmored heavilyArmored=true; if(t.equals("armed")) { speed=50; armament=30; capacity=8; armed=true; } else if(t.equals("light")) { speed=70; armament=10; capacity=20; armed=false; } else { speed=60; armament=10; capacity=25; armed=false; } } // accessor for new instance datum public boolean isArmed() { return armed; } // override parent methods based on new instance data and logic @Override public String toString() { return super.toString() + " and is armed " + armed; } // good choice if ground support isn eeded and need arms and/or equipment, limited distance @Override public int getBattleUtility(boolean night, boolean roughTerrain, boolean needGroundSupport, boolean needHeavyArms, boolean antiAircraftGuns, boolean equipment, int distance) { int score=super.getBattleUtility(night,roughTerrain,needGroundSupport,needHeavyArms,antiAircraftGuns,equipment,distance); if(needGroundSupport) score+=capacity*2; if(distance<=getDistance()) score+=7; else score-=33; if(needHeavyArms&&armed) score+=armament; else score+=5; if(equipment) score+=10; return score; } }