import java.util.stream.Stream;
import java.util.stream.DoubleStream;
import java.util.Arrays;
import java.util.function.Function;

public class Main {
    static final double[] percents   = {0.10, 0.15, 0.25, 0.28, 0.33, 0.35};
    static final double[] thresholds = {8350, 33950, 82250, 171550, 372950};

    public static void main(String[] args) {
        double[] partialSums = Stream.iterate(0, n -> n + 1).limit(5).mapToDouble(
            (i) -> thresholds[i] * (percents[i] - percents[i + 1])
        ).toArray();

        Function<Double, Double> computeTax = (income) -> {
            int level = (int)Arrays.stream(thresholds).reduce(0, (x, y) -> x + new Boolean(income > y).compareTo(false));

            return Arrays.stream(partialSums).limit(level).reduce(0, (x, y) -> x + y) + income * percents[level];
        };

        double tax = computeTax.apply(100000.0);
        double controlValue = 8350 * 0.10 + (33950 - 8350) * 0.15 +
            (82250 - 33950) * 0.25 + (100000 - 82250) * 0.28;
        System.out.println("Tax is " + (int)(tax * 100) / 100.0);
        System.out.println("Control value is " + (int)(tax * 100) / 100.0);
    }
}
