编程珠玑-课后练习题3

计算税率表达式简化

 1 package third;
 2 
 3 public class SimpleTax {
 4     public static double getTax(double income) {
 5         double index = (income - 2200) / 500;
 6         double tax = 0;
 7         double startRate = 0.14;
 8         if (index <= 0) {
 9             tax = 0;
10         } else {
11             for (int i = 1; i <= index; i++) {
12                 tax = tax + startRate * 500;
13                 startRate += 0.01;
14             }
15             tax += (income - 2200 - 500 * ((int) index)) * startRate;
16         }
17         return tax;
18     }
19 
20     public static void main(String[] args) {
21         System.out.println(getTax(3700));
22     }
23 
24 }

 

posted @ 2016-01-03 21:19  程序猿进化之路  阅读(124)  评论(0)    收藏  举报