2. 如果当前的⼯工资到这⼀一档就到头了了,需要break
给出⼀一⼀一个2D数组代表tax bracket[[10000,.1],[8000,.2],[6000,.3],[null, .
4]],求 effective tax
给你⼀一些list, ⾥里里⾯面存的是关于⼯工资收税的信息。⽐比如{{1000,0.1},
{2000,0.2},{null, 0.4}}. 还给了了员⼯工的salary。 让你根据这个list中的信
息来计算员⼯工最后要交多少税
https://github.com/mintycc/OnlineJudge-Solutions/blob/master/untag/Tax%20Calculator/TaxCalculator.java
给出⼀一⼀一个2D数组代表tax bracket[[10000,.1],[8000,.2],[6000,.3],[null, .
4]],求 effective tax
给你⼀一些list, ⾥里里⾯面存的是关于⼯工资收税的信息。⽐比如{{1000,0.1},
{2000,0.2},{null, 0.4}}. 还给了了员⼯工的salary。 让你根据这个list中的信
息来计算员⼯工最后要交多少税
https://github.com/mintycc/OnlineJudge-Solutions/blob/master/untag/Tax%20Calculator/TaxCalculator.java
    public static class Tax {
        double base, rate;
        public Tax(double base, double rate) {
            this.base = base;
            this.rate = rate;
        }
    }
    public double calculate(Tax[] taxs, double money) {
        Arrays.sort(taxs, new Comparator<Tax>(){
            public int compare(Tax a, Tax b) {
                if (a.base < b.base) return -1;
                else if (a.base == b.base) return 0;
                else return 1;
            }
        });
        double pay = 0;
        for (int i = 0; i < taxs.length; i ++) {
            if (i < taxs.length - 1 && money >= taxs[i + 1].base)
                pay += (taxs[i + 1].base - taxs[i].base) * taxs[i].rate;
            else {
                pay += (money - taxs[i].base) * taxs[i].rate;
                break;
            }
        }
        return pay;
    }
    public static void main(String[] args) {
        TaxCalculator sol = new TaxCalculator();
        Tax[] taxs = new Tax[4];
        taxs[0] = new Tax(10000, 0.1);
        taxs[1] = new Tax(8000, 0.2);
        taxs[2] = new Tax(6000, 0.3);
        taxs[3] = new Tax(0, 0.4);
        System.out.println(sol.calculate(taxs, 4000));
    }
