Java语言程序设计 例题3.13(计算税款)

*3.13
(Financial application: compute taxes) Listing 3.5, ComputeTax.java, gives the 
source code to compute taxes for single filers. Complete Listing 3.5 to compute 
the taxes for all filing statuses.

*3.13

(金融应用:计算税款)清单3.5给出了为单个申报者计算税收的源代码.完成清单3.5来计算所有归档状态的税收

代码如下

import java.util.Scanner;
 
  public class Unite3Test13 
  {
  public static void main(String[] args) 
  {

  Scanner input = new Scanner(System.in);
 
  System.out.print("(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();
 System.out.print("Enter the taxable income: ");
 double income = input.nextDouble();
 double tax = 0;
 if (status == 0) { 
 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 + (33950 - 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) { 
	 if (income <= 16700)
		 tax = income * 0.10;
		 else if (income <= 67900)
		 tax = 16700 * 0.10 + (income - 16700) * 0.15;
		 else if (income <= 137050)
		 tax =  16700  * 0.10 + (67900 - 16700) * 0.15 +(income - 67900) * 0.25;
		 else if (income <= 208850)
		 tax =  16700 * 0.10 +(67900 - 16700) * 0.15 +(137050-67900) * 0.25 + (income - 137050) * 0.28;
		 else if (income <= 372950)
		 tax =  16700  * 0.10 + (67900 - 16700)* 0.15 +(137050-67900) * 0.25 + (208850 - 137050) * 0.28 +(income - 208850) * 0.33;
		 else
		 tax =  16700  * 0.10 +(67900 - 16700) * 0.15 +(137050-67900) * 0.25 + (208850 - 137050) * 0.28 +(372950 - 208850) * 0.33 + (income - 372950) * 0.35;
		 }

 else if (status == 2) 
 {
	 if (income <= 8350)
		 tax = income * 0.10;
		 else if (income <= 33950)
		 tax = 8350 * 0.10 + (income - 8350) * 0.15;
		 else if (income <= 68525)
		 tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(income - 33950) * 0.25;
		 else if (income <= 104425)
		 tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(68525 - 33950) * 0.25 + (income - 68525) * 0.28;
		 else if (income <= 186475)
		 tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(68525 - 33950) * 0.25 + (104425-68525) * 0.28 +(income - 104425) * 0.33;
		 else
		 tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +(68525 - 33950) * 0.25 + (104425-68525) * 0.28 +(186475 - 104425) * 0.33 + (income - 186475) * 0.35;
		 }
 
 else if (status == 3) 
 { 
	 if (income <= 11950)
		 tax = income * 0.10;
		 else if (income <= 45500)
		 tax = 11950* 0.10 + (income - 11950) * 0.15;
		 else if (income <= 117450)
		 tax = 11950 * 0.10 + (45500 - 11950) * 0.15 +(income - 45500) * 0.25;
		 else if (income <= 190200)
		 tax =11950 * 0.10 + (45500 - 11950) * 0.15 +(117450 - 45500) * 0.25 + (income - 117450) * 0.28;
		 else if (income <= 372950)
		 tax = 11950 * 0.10 + (45500 - 11950) * 0.15 +(117450 - 45500) * 0.25 + (190200-117450) * 0.28 +(income - 190200) * 0.33;
		 else
		 tax = 11950 * 0.10 + (45500 - 11950) * 0.15 +(117450 - 45500) * 0.25 + (190200-117450) * 0.28 +(372950 - 190200) * 0.33 + (income - 372950) * 0.35;
		 }
	 

 
 else {
 System.out.println("Error: invalid status");
 System.exit(1);
 }


 System.out.println("Tax is " + (int)(tax * 100) / 100.0);
 }
 }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

差劲的厉害了

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值