// repairs an army as much as its wealth will allow it. public void repair(PartyType pt) { // returns a repair cost int newSize = pt.getRandomSize(); int missing = Math.max(newSize - this.getTotalSize(), 0); // no negative ints // int totalCost = 0; boolean canAfford = true; while (missing > 0 && canAfford) { Soldier newSoldier = new Soldier(pt.randomSoldierType(), this); int cost = newSoldier.getCost(); if (this.wealth > cost) { this.addSoldier(newSoldier); this.wealth -= cost; missing--; } else { canAfford = false; } } System.out.println("party repaired"); }