题目
2019年1月1日起,国家推出新的个人所得税政策,起征点上调值5000元。也就是说税前工资扣除三险一金(三险一金数额假设是税前工资的10%)后如果不足5000元,则不交税。如果大于5000元,那么大于5000元的部分按梯度交税,具体梯度比例如下:
0 ~ 3000元的部分,交税3%
3000 ~ 12000元的部分,交税10%
12000 ~ 25000的部分 , 交税20%
25000 ~ 35000的部分,交税25%
35000 ~ 55000的部分,交税30%
55000 ~ 80000的部分,交税35%
超过80000的部分,交税45%
比如:坏蛋阿瑞入职一家企业后,税前工资是15000,则他每月该交个税的部分是15000-1500-5000=8500元,个税缴纳数额是3000×3%+5500×10%=640元。税后工资12860元。
请完成一个个税计算程序,在用户输入税前工资后,计算出他对应的纳税数额,以及税后工资为多少?
解题提示
1. 工资的哪些部分是属于要纳税部分,如何计算?
2. 纳税比例有很多区间,用什么知识点能够对应多个区间?
3. 每个区间的纳税数额是多少,计算的规律是什么?
4.可以考虑使用多条件的if...else对应各个纳税梯度,分别计算每一个梯度的纳税数额。
操作步骤
1. 提示用户输入税前工资,使用键盘录入让用户输入一个整数。
2. 计算工资中应交税部分。也就是去除三险一金和起征点数额。
3. 使用多条件if..else..对每个区间分别判断,用每个梯度的计算公式求出对应的纳税数额。
4. 根据求出的纳税数额求出税后工资。
详细代码
package Package1;
import java.util.Scanner;
public class Tax {
public static void main(String[] args) {
System.out.println("请输入您的税前收入");
Scanner sc = new Scanner(System.in);
double beforeTax = sc.nextDouble(); //录入税前收入
double afterSocialSecurity = beforeTax - beforeTax * 0.1; //缴纳社保后的收入
double afterTax = afterSocialSecurity - 5000; //减去征税起步的金额
double tax55000_80000 = (80000 - 55000) * 0.35;
double tax35000_55000 = (55000 - 35000) * 0.3;
double tax25000_35000 = (35000 - 25000) * 0.25;
double tax12000_25000 = (25000 - 12000) * 0.2;
double tax3000_12000 = (12000 - 3000) * 0.1;
double tax0_3000 = 3000 * 0.03;
if (afterTax >= 80000) { //收入在80000以上的交0.45
afterTax = afterTax - (afterTax - 80000) * 0.45 - tax55000_80000 - tax35000_55000 - tax25000_35000 - tax12000_25000 - tax3000_12000 - tax0_3000;
}
if (afterTax >= 55000 && afterTax < 80000) { //收入在55000-80000的部分交0.35
afterTax = afterTax - (afterTax - 55000) * 0.35 - tax35000_55000 - tax25000_35000 - tax12000_25000 - tax3000_12000 - tax0_3000;
}
if (afterTax >= 35000 && afterTax < 55000) { //收入35000-55000的部分交0.3
afterTax = afterTax - (afterTax - 35000) * 0.3 - tax25000_35000 - tax12000_25000 - tax3000_12000 - tax0_3000;
}
if (afterTax >= 25000 && afterTax <35000) { //收入25000-35000的部分交0.25
afterTax = afterTax - (afterTax - 25000) * 0.25 - tax12000_25000 - tax3000_12000 - tax0_3000;
}
if (afterTax >=12000 && afterTax < 25000) { //收入12000-25000的部分交0.2
afterTax = afterTax - (afterTax - 12000) * 0.2 - tax3000_12000 - tax0_3000;
}
if (afterTax >= 3000 && afterTax < 12000) { //收入3000-12000的部分交0.1
afterTax = afterTax - (afterTax - 3000) * 0.1 - tax0_3000;
}
if (afterTax < 3000 ) { //3000的部分交0.03
afterTax = afterTax - afterTax * 0.03;
}
afterTax = afterTax + 5000;
System.out.println("您的税后收入为: " + afterTax);
}
}