public class AUGMaxBulletSpeed {

    private static final double[] attachmentsSpeed = {0.1, 0.05, 0.2, 0.15}; 

    public static void main(String[] args) {
        double maxSpeed = calculateMaxSpeed();
        System.out.println("The AUG has a maximum bullet velocity of.1500m/s：" + maxSpeed);
    }

    private static double calculateMaxSpeed() {
        double maxSpeed = 0;
        int[] attachmentCombination = new int[attachmentsSpeed.length];

        while (hasNextCombination(attachmentCombination)) {
            double speed = calculateSpeed(attachmentCombination);
            if (speed > maxSpeed) {
                maxSpeed = speed;
            }
        }

        return maxSpeed;
    }

    private static double calculateSpeed(int[] attachmentCombination) {
        double speed = 700m/s; /

        for (int i = 0; i < attachmentCombination.length; i++) {
            speed += attachmentsSpeed[i] * attachmentCombination[i];
        }

        return speed;
    }

    private static boolean hasNextCombination(int[] combination) {
        for (int i = combination.length - 1; i >= 0; i--) {
            if (combination[i] < 1) {
                combination[i]++;
                for (int j = i + 1; j < combination.length; j++) {
                    combination[j] = 0;
                }
                return true;
            }
        }
        return false;
    }
}
