import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Scanner;
public class tax {
public static void main(String[] args) {
System.out.println("个税计算器\n请输入税前工资");
Scanner sc = new Scanner(System.in);
DecimalFormat decimalFormat = new DecimalFormat("#.00");
// 创建一个DecimalFormat 对象,并指定格式模式
BigDecimal taxAmountPayable = new BigDecimal(0);
// 应纳税额
BigDecimal salary = sc.nextBigDecimal();
// 税前工资
BigDecimal afterTaxIncome = new BigDecimal(0);
// 税后工资
BigDecimal salary1 = salary.subtract(salary.multiply(new BigDecimal(0.1))).subtract(new BigDecimal(5000));
// 应纳税部分的工资
if (salary1.compareTo(new BigDecimal(3000)) == -1 && salary1.compareTo(new BigDecimal(0)) == 1){
taxAmountPayable = salary1.multiply(new BigDecimal(0.03));
afterTaxIncome = (salary.subtract(salary).multiply(new BigDecimal(0.1)).subtract(salary1).multiply(new BigDecimal(0.03)));
}
// 0 ~ 3000元的部分,交税3%
else if (salary1.compareTo(new BigDecimal(12000)) == -1 && salary1.compareTo(new BigDecimal(3000)) == 1){
taxAmountPayable = ((salary1.subtract(new BigDecimal(3000))).multiply(new BigDecimal(0.1)).add(new BigDecimal(90)));
afterTaxIncome = (salary.subtract((salary).multiply(new BigDecimal(0.1))).subtract(((salary1.subtract(new BigDecimal(3000))).multiply(new BigDecimal(0.1)).add(new BigDecimal(3000*0.03)))));
}
// 3000 ~ 12000元的部分,交税10%
else if (salary1.compareTo(new BigDecimal(25000)) == -1 && salary1.compareTo(new BigDecimal(12000)) == 1){
taxAmountPayable = salary1.subtract(new BigDecimal(12000)).multiply(new BigDecimal(0.2)).add(new BigDecimal(990));
afterTaxIncome = salary.subtract(salary).multiply(new BigDecimal(0.1)).subtract(salary1.subtract(new BigDecimal(12000))).multiply(new BigDecimal(0.2)).subtract(new BigDecimal(990));
}
// "税后到手"+(salary-salary*0.1-(990+(salary1-12000)*0.2)));
// 12000 ~ 25000的部分 , 交税20%
else if (salary1.compareTo(new BigDecimal(35000)) == -1 && salary1.compareTo(new BigDecimal(25000)) == 1){
taxAmountPayable = salary1.subtract(new BigDecimal(25000)).multiply(new BigDecimal(0.25)).add(new BigDecimal(3590));
afterTaxIncome = salary.subtract(salary).multiply(new BigDecimal(0.1)).subtract(salary1.subtract(new BigDecimal(25000))).multiply(new BigDecimal(0.25)).subtract(new BigDecimal(3590));
}
// "税后到手"+(salary-salary*0.1-(3000*0.03+9000*0.1+13000*0.2+(salary1-25000)*0.25)));
// 25000 ~ 35000的部分,交税25%
else if (salary1.compareTo(new BigDecimal(55000)) == -1 && salary1.compareTo(new BigDecimal(35000)) == 1){
taxAmountPayable = salary1.subtract(new BigDecimal(35000)).multiply(new BigDecimal(0.3)).add(new BigDecimal(6090));
afterTaxIncome = salary.subtract(salary).multiply(new BigDecimal(0.1)).subtract(salary1.subtract(new BigDecimal(35000))).multiply(new BigDecimal(0.3)).subtract(new BigDecimal(6090));
}
// "税后到手"+(salary-salary*0.1-(3000*0.03+9000*0.1+13000*0.2+10000*0.25+(salary1-35000)*0.3)));
// 35000 ~ 55000的部分,交税30%
else if (salary1.compareTo(new BigDecimal(80000)) == -1 && salary1.compareTo(new BigDecimal(55000)) == 1){
taxAmountPayable = salary1.subtract(new BigDecimal(55000)).multiply(new BigDecimal(0.35)).add(new BigDecimal(12090));
afterTaxIncome = salary.subtract(salary).multiply(new BigDecimal(0.1)).subtract(salary1.subtract(new BigDecimal(55000))).multiply(new BigDecimal(0.35)).subtract(new BigDecimal(12090));
}
// "税后到手"+(salary-salary*0.1-(3000*0.03+9000*0.1+13000*0.2+10000*0.25+20000*0.3+(salary1-55000)*0.35)));
// 55000 ~ 80000的部分,交税35%
else if (salary1.compareTo(new BigDecimal(80000)) == 1){
taxAmountPayable = salary1.subtract(new BigDecimal(80000)).multiply(new BigDecimal(0.45)).add(new BigDecimal(20840));
afterTaxIncome = salary.subtract(salary).multiply(new BigDecimal(0.1)).subtract(salary1.subtract(new BigDecimal(80000))).multiply(new BigDecimal(0.45)).subtract(new BigDecimal(20840));
}
// "税后到手"+(salary-salary*0.1-(3000*0.03+9000*0.1+13000*0.2+10000*0.25+20000*0.3+25000*0.35+(salary1-80000)*0.45))+"\n牛逼啊哥们!");
// 超过80000的部分,交税45%
// 使用 DecimalFormat 对象格式化金额
String taxAmountPayable1 = decimalFormat.format(taxAmountPayable);
String afterTaxIncome1 = decimalFormat.format(afterTaxIncome);
System.out.println("应缴纳个人所得税为:"+ taxAmountPayable1+"税后到手"+afterTaxIncome1);
}
}
个税计算器,用BigDecimal实现
最新推荐文章于 2024-09-05 11:00:53 发布