第六章第十五题(金融应用:打印税表)(Financial application: print a tax table)

第六章第十五题(金融应用:打印税表)(Financial application: print a tax table)

  • *6.15(金融应用:打印税表)程序清单3-5给出了计算税款的程序。使用税款的程序。使用下面的方法头编写一个计算税款的方法:
    public static double computeTax(int status,double taxableIncome)
    使用这个方法编写程序,打印可征税收人从50000美元到60000美元,收入间隔为50美元的所有以下婚姻状态的纳税表,如下所示:
    Taxable Single Married Joint Married Head of
    Income or Qualifying Separate House hold
    Widow(er)
    50000 8688 6665 8688 7353
    50050 8700 6673 8700 7365

    59950 11175 8158 11175 9840
    60000 11188 8165 11188 9853
    提示:使用Math.round(即Math.round(computeTax(status,tabableIncome)))将税收舍入为整数。
    *6.15(Financial application: print a tax table) Listing 3.5 gives a program to compute tax. Write a method for computing tax using the following header:
    public static double computeTax(int status, double taxableIncome)
    Use this method to write a program that prints a tax table for taxable income from $50,000 to $60,000 with intervals of $50 for
    all the following statuses:
    Taxable Single Married Joint Married Head of
    Income or Qualifying Separate House hold
    Widow(er)
    50000 8688 6665 8688 7353
    50050 8700 6673 8700 7365

    59950 11175 8158 11175 9840
    60000 11188 8165 11188 9853
    Hint: round the tax into integers using Math.round (i.e., Math .round(computeTax(status, taxableIncome))).
  • 参考代码:
package chapter06;

public class Code_15 {
    public static void main(String[] args) {
        printTableHead();
        for(int i = 50000;i <= 60000;i += 50) {
            System.out.printf("%d\t\t", i);
            System.out.printf("%d\t\t", Math.round(computeTax(0,i)));
            System.out.printf("%d\t\t\t", Math.round(computeTax(1,i)));
            System.out.printf("%d\t\t", Math.round(computeTax(2,i)));
            System.out.printf("%d\n", Math.round(computeTax(3,i)));
        }
    }
    public static double computeTax(int status,double taxableIncome) {
        double tax = 0;
        if (status == 0) {
            if (taxableIncome <= 8350)
                tax = taxableIncome * 0.10;
            else if (taxableIncome <= 33950)
                tax = 8350 * 0.10 + (taxableIncome - 8350) * 0.15;
            else if (taxableIncome <= 82250)
                tax = 8350 * 0.10 + (33950 - 8350) * 0.15
                        +(taxableIncome - 33950) * 0.25;
            else if (taxableIncome <= 171550)
                tax = 8350 * 0.10 + (33950 - 8350) * 0.15
                        +(82250 - 33950) * 0.25 + (taxableIncome - 82250) * 0.28;
            else if (taxableIncome <= 372950)
                tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
                        (82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 +
                        (taxableIncome - 171550) * 0.33;
            else
                tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
                        (82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 +
                        (372950 - 171550) * 0.33 + (taxableIncome - 372950) * 0.35;
        }
        else if (status == 1) {
            if (taxableIncome <= 16700)
                tax = taxableIncome * 0.10;
            else if (taxableIncome <= 67900)
                tax = 16700 * 0.10 + (taxableIncome - 16700) * 0.15;
            else if (taxableIncome <= 137050)
                tax = 16700 * 0.10 + (67900 - 16700) * 0.15
                        +(taxableIncome - 67900) * 0.25;
            else if (taxableIncome <= 208850)
                tax = 16700 * 0.10 + (67900 - 16700) * 0.15
                        +(137050 - 67900) * 0.25 + (taxableIncome - 137050) * 0.28;
            else if (taxableIncome <= 372950)
                tax = 16700  * 0.10 + (67900 - 16700) * 0.15 +
                        (137050 - 67900) * 0.25 + (208850 - 137050) * 0.28 +
                        (taxableIncome - 208850) * 0.33;
            else
                tax = 16700 * 0.10 + (67900 - 16700) * 0.15 +
                        (137050 - 67900) * 0.25 + (208850 - 137050) * 0.28 +
                        (372950 - 208850) * 0.33 + (taxableIncome - 372950) * 0.35;
        }
        else if (status == 2) {
            if (taxableIncome <= 8350)
                tax = taxableIncome * 0.10;
            else if (taxableIncome <= 33950)
                tax = 8350 * 0.10 + (taxableIncome - 8350) * 0.15;
            else if (taxableIncome <= 68525)
                tax = 8350 * 0.10 + (33950 - 8350) * 0.15
                        +(taxableIncome - 33950) * 0.25;
            else if (taxableIncome <= 104425)
                tax = 8350 * 0.10 + (33950 - 8350) * 0.15
                        +(68525 - 33950) * 0.25 + (taxableIncome - 68525) * 0.28;
            else if (taxableIncome <= 186475)
                tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
                        (68525 - 33950) * 0.25 + (104425 - 68525) * 0.28 +
                        (taxableIncome - 104425) * 0.33;
            else
                tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
                        (68525 - 33950) * 0.25 + (104425 - 68525) * 0.28 +
                        (186475 - 104425) * 0.33 + (taxableIncome - 186475) * 0.35;
        }
        else if (status == 3) {
            if (taxableIncome <= 11950)
                tax = taxableIncome * 0.10;
            else if (taxableIncome <= 45500)
                tax = 11950 * 0.10 + (taxableIncome - 11950) * 0.15;
            else if (taxableIncome <= 117450)
                tax = 11950 * 0.10 + (45500 - 11950) * 0.15
                        +(taxableIncome - 45500) * 0.25;
            else if (taxableIncome <= 190200)
                tax = 11950 * 0.10 + (45500 - 11950) * 0.15
                        +(117450 - 45500) * 0.25 + (taxableIncome - 117450) * 0.28;
            else if (taxableIncome <= 372950)
                tax = 11950 * 0.10 + (45500 - 11950) * 0.15 +
                        (117450 - 45500) * 0.25 + (190200 - 117450) * 0.28 +
                        (taxableIncome - 190200) * 0.33;
            else
                tax = 11950 * 0.10 + (45500 - 11950) * 0.15 +
                        (117450 - 45500) * 0.25 + (190200 - 117450) * 0.28 +
                        (372950 - 190200) * 0.33 + (taxableIncome - 372950) * 0.35;
        }
        else
            return -1;
        return tax;
    }
    public static void printTableHead() {
        System.out.println("Taxable\t\tSingle\t\tMarried Joint\t\tMarried\t\tHead of");
        System.out.println("Income\t\t\t\tor Qualifying\t\tSeparate\tHouse hold");
        System.out.println("\t\t\t\tWidow(er)");
        System.out.print("-----------------------------------------");
        System.out.print("-----------------------------------------\n");
    }
}

  • 结果显示:
Taxable		Single		Married Joint		Married		Head of
Income				or Qualifying		Separate	House hold
				Widow(er)
----------------------------------------------------------------------------------
50000		8688		6665			8688		7353
50050		8700		6673			8700		7365
50100		8713		6680			8713		7378
50150		8725		6688			8725		7390
50200		8738		6695			8738		7403
50250		8750		6703			8750		7415
50300		8763		6710			8763		7428
50350		8775		6718			8775		7440
50400		8788		6725			8788		7453
50450		8800		6733			8800		7465
50500		8813		6740			8813		7478
50550		8825		6748			8825		7490
50600		8838		6755			8838		7503
50650		8850		6763			8850		7515
50700		8863		6770			8863		7528
50750		8875		6778			8875		7540
50800		8888		6785			8888		7553
50850		8900		6793			8900		7565
50900		8913		6800			8913		7578
50950		8925		6808			8925		7590
51000		8938		6815			8938		7603
51050		8950		6823			8950		7615
51100		8963		6830			8963		7628
51150		8975		6838			8975		7640
51200		8988		6845			8988		7653
51250		9000		6853			9000		7665
51300		9013		6860			9013		7678
51350		9025		6868			9025		7690
51400		9038		6875			9038		7703
51450		9050		6883			9050		7715
51500		9063		6890			9063		7728
51550		9075		6898			9075		7740
51600		9088		6905			9088		7753
51650		9100		6913			9100		7765
51700		9113		6920			9113		7778
51750		9125		6928			9125		7790
51800		9138		6935			9138		7803
51850		9150		6943			9150		7815
51900		9163		6950			9163		7828
51950		9175		6958			9175		7840
52000		9188		6965			9188		7853
52050		9200		6973			9200		7865
52100		9213		6980			9213		7878
52150		9225		6988			9225		7890
52200		9238		6995			9238		7903
52250		9250		7003			9250		7915
52300		9263		7010			9263		7928
52350		9275		7018			9275		7940
52400		9288		7025			9288		7953
52450		9300		7033			9300		7965
52500		9313		7040			9313		7978
52550		9325		7048			9325		7990
52600		9338		7055			9338		8003
52650		9350		7063			9350		8015
52700		9363		7070			9363		8028
52750		9375		7078			9375		8040
52800		9388		7085			9388		8053
52850		9400		7093			9400		8065
52900		9413		7100			9413		8078
52950		9425		7108			9425		8090
53000		9438		7115			9438		8103
53050		9450		7123			9450		8115
53100		9463		7130			9463		8128
53150		9475		7138			9475		8140
53200		9488		7145			9488		8153
53250		9500		7153			9500		8165
53300		9513		7160			9513		8178
53350		9525		7168			9525		8190
53400		9538		7175			9538		8203
53450		9550		7183			9550		8215
53500		9563		7190			9563		8228
53550		9575		7198			9575		8240
53600		9588		7205			9588		8253
53650		9600		7213			9600		8265
53700		9613		7220			9613		8278
53750		9625		7228			9625		8290
53800		9638		7235			9638		8303
53850		9650		7243			9650		8315
53900		9663		7250			9663		8328
53950		9675		7258			9675		8340
54000		9688		7265			9688		8353
54050		9700		7273			9700		8365
54100		9713		7280			9713		8378
54150		9725		7288			9725		8390
54200		9738		7295			9738		8403
54250		9750		7303			9750		8415
54300		9763		7310			9763		8428
54350		9775		7318			9775		8440
54400		9788		7325			9788		8453
54450		9800		7333			9800		8465
54500		9813		7340			9813		8478
54550		9825		7348			9825		8490
54600		9838		7355			9838		8503
54650		9850		7363			9850		8515
54700		9863		7370			9863		8528
54750		9875		7378			9875		8540
54800		9888		7385			9888		8553
54850		9900		7393			9900		8565
54900		9913		7400			9913		8578
54950		9925		7408			9925		8590
55000		9938		7415			9938		8603
55050		9950		7423			9950		8615
55100		9963		7430			9963		8628
55150		9975		7438			9975		8640
55200		9988		7445			9988		8653
55250		10000		7453			10000		8665
55300		10013		7460			10013		8678
55350		10025		7468			10025		8690
55400		10038		7475			10038		8703
55450		10050		7483			10050		8715
55500		10063		7490			10063		8728
55550		10075		7498			10075		8740
55600		10088		7505			10088		8753
55650		10100		7513			10100		8765
55700		10113		7520			10113		8778
55750		10125		7528			10125		8790
55800		10138		7535			10138		8803
55850		10150		7543			10150		8815
55900		10163		7550			10163		8828
55950		10175		7558			10175		8840
56000		10188		7565			10188		8853
56050		10200		7573			10200		8865
56100		10213		7580			10213		8878
56150		10225		7588			10225		8890
56200		10238		7595			10238		8903
56250		10250		7603			10250		8915
56300		10263		7610			10263		8928
56350		10275		7618			10275		8940
56400		10288		7625			10288		8953
56450		10300		7633			10300		8965
56500		10313		7640			10313		8978
56550		10325		7648			10325		8990
56600		10338		7655			10338		9003
56650		10350		7663			10350		9015
56700		10363		7670			10363		9028
56750		10375		7678			10375		9040
56800		10388		7685			10388		9053
56850		10400		7693			10400		9065
56900		10413		7700			10413		9078
56950		10425		7708			10425		9090
57000		10438		7715			10438		9103
57050		10450		7723			10450		9115
57100		10463		7730			10463		9128
57150		10475		7738			10475		9140
57200		10488		7745			10488		9153
57250		10500		7753			10500		9165
57300		10513		7760			10513		9178
57350		10525		7768			10525		9190
57400		10538		7775			10538		9203
57450		10550		7783			10550		9215
57500		10563		7790			10563		9228
57550		10575		7798			10575		9240
57600		10588		7805			10588		9253
57650		10600		7813			10600		9265
57700		10613		7820			10613		9278
57750		10625		7828			10625		9290
57800		10638		7835			10638		9303
57850		10650		7843			10650		9315
57900		10663		7850			10663		9328
57950		10675		7858			10675		9340
58000		10688		7865			10688		9353
58050		10700		7873			10700		9365
58100		10713		7880			10713		9378
58150		10725		7888			10725		9390
58200		10738		7895			10738		9403
58250		10750		7903			10750		9415
58300		10763		7910			10763		9428
58350		10775		7918			10775		9440
58400		10788		7925			10788		9453
58450		10800		7933			10800		9465
58500		10813		7940			10813		9478
58550		10825		7948			10825		9490
58600		10838		7955			10838		9503
58650		10850		7963			10850		9515
58700		10863		7970			10863		9528
58750		10875		7978			10875		9540
58800		10888		7985			10888		9553
58850		10900		7993			10900		9565
58900		10913		8000			10913		9578
58950		10925		8008			10925		9590
59000		10938		8015			10938		9603
59050		10950		8023			10950		9615
59100		10963		8030			10963		9628
59150		10975		8038			10975		9640
59200		10988		8045			10988		9653
59250		11000		8053			11000		9665
59300		11013		8060			11013		9678
59350		11025		8068			11025		9690
59400		11038		8075			11038		9703
59450		11050		8083			11050		9715
59500		11063		8090			11063		9728
59550		11075		8098			11075		9740
59600		11088		8105			11088		9753
59650		11100		8113			11100		9765
59700		11113		8120			11113		9778
59750		11125		8128			11125		9790
59800		11138		8135			11138		9803
59850		11150		8143			11150		9815
59900		11163		8150			11163		9828
59950		11175		8158			11175		9840
60000		11188		8165			11188		9853

Process finished with exit code 0

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值