Java黑皮书课后题第6章:*6.15(金融应用:打印税表)程序清单3-5给出了计算税款的程序。使用下面的方法体编写一个计算税款的方法。使用这个方法编写程序,打印可征税人从50000到60000间隔

*6.15(金融应用:打印税表)程序清单3-5给出了计算税款的程序。使用下面的方法体编写一个计算税款的方法。使用这个方法编写程序

题目

题目描述

*6.15(金融应用:打印税表)程序清单3-5给出了计算税款的程序。
使用下面的方法体编写一个计算税款的方法:
public static double computeTax(int status, double taxableIncome)
使用这个方法编写程序,打印可征税收入从50 000美元到60 000美元,收入间隔为50美元的所有以下婚姻状态的纳税表,如图所示:

原书提示:使用Math.round将税收舍入为整数,即:Math.round(computeTax(status, taxableIncome))

破题

status参数对应婚姻状态,在computeTax()这个计算税款的方法中,需要status参数的数值来确定不同层次税率
computeTax()仅完成税款计算其它功能,其它功能均由主方法承担

程序清单3-5(非本题):代码不全

import java.util.Scanner;

public class qingdan {
   
    public static void main(String[] args) {
   
        // Create a Scanner
        Scanner input = new Scanner(System.in);

        // Prompt the user to enter filing status
        System.out.println("(0-single filer, 1-married jointly or " +
                "qualifying widow(er), 2-married separately, 3-head of " +
                "household) Enter the filing status:");

        int status = input.nextInt();

        // Prompt the user to enter taxable income
        System.out.println("Enter the taxable income:");
        double income = input.nextDouble();

        // compute tax
        double tax = 0;

        if (status == 0) {
      // Compute tax for single filers
            if (income <= 8350)
                tax = income * 0.10;
            else if(income <= 33950)
                tax = 8350 * 0.10 + (income - 8350) * 0.15;
            else if(income <= 82250)
                tax = 8350 * 0.10 + (income - 8350) * 0.15 +
                        (income - 33950) * 0.25;
            else  if(income <= 171550)
                tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
                        (82250 - 33950) * 0.25 + (income - 82250) * 0.28;
            else  if(income <= 372950)
                tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
                        (82250 - 33950) * 0.25 +(171550 - 82250) * 0.28 +
                        (income - 171550) * 0.33;
            else
                tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
                        (82250 - 33950) * 0.25 +(171550 - 82250) * 0.28 +
                        (372950 - 171550) * 0.33 + (income - 372950) * 0.35;
        }else if(status == 1){
     // Left as an exercise
            // Compute tax for married file jointly or qualifying widow(er)
        }else if(status == 2){
     // Left as an exercise
        }else if(status == 3){
     // Left as an exercise
        }else{
   
            System.out.println("Error: invalid status");
            System.exit(1);
        }
        // Display the result
        System.out.println("Tax is " + (int)(tax * 100) / 100.0);
    }
}

补充代码:编程练习题3.13 / 程序清单3-5完善版

点击这里快速跳转我的3.15博文,或复制URL到浏览器:

https://blog.csdn.net/weixin_46356698/article/details/119806167

import java.util.Scanner;

public class Test3_13 {
   
    public static void main(String[] args) {
   
        // Create a Scanner
        Scanner input = new Scanner(System.in);

        // Prompt the user to enter filing status
        System.out.println("(0-single filer, 1-married jointly or " +
                "qualifying widow(er), 2-married separately, 3-head of " +
                "household) Enter the filing status:");
        int status = input.nextInt();

        // Prompt the user to enter taxable income
        System.out.println("Enter the taxable income:");
        double income = input.nextDouble()
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值