Java黑皮书课后题第8章:**8.12(金融应用:计算税款)使用数组重写程序清单3-5,每个纳税人身份都有6种税率。每种税率都应用在某个特定范围内的可征税收入

**8.12(金融应用:计算税款)使用数组重写程序清单3-5

题目

题目描述

**8.12(金融应用:计算税款)使用数组重写程序清单3-5。
每个纳税人身份都有6种税率,每种税率都应用在某个特定范围内的可征税收入。
比如,对于一个单身纳税人,六种税率可以用下面的数组表示:
double[] rates = {0.10, 0.15, 0.25, 0.28, 0.33, 0.35};
所有纳税人身份针对各个税率的纳税等级可以用一个二维数组表示,如下所示:
int[][] brackets = {
{8350, 39500, 82250, 171550, 372950}, // Single filer(0)
{16700, 69000, 137050, 20885, 372950}, // Married jointly qualifying widow(er)(1)
{8350, 33950, 68525, 104425, 186475}, // Married separately(2)
{11950, 45500, 117450, 190200, 372950}, // Head of household(3)
};
假设单身身份的纳税人的可征税收入是400 000美元,则税收可以如下计算:
tax = brackets[0][0] * rates[0] +
(brackets[0][1] - brackets[0][0]) * rates[1] +
(brackets[0][2] - brackets[0][1]) * rates[2] +
(brackets[0][3] - brackets[0][2]) * rates[3] +
(brackets[0][4] - brackets[0][3]) * rates[4] +
(400000 - brackets[0][4]) * rates[5];

程序清单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 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值