使用系统:Windows10;
使用JDK:Java SE Development Kit 17.0.2;
使用开发环境:eclipse。
一、代码
package javajichu; import java.util.Scanner; public class SuiFei { public static void main(String[] args) { System.out.println("按工资标准缴纳相应的税费:"); Scanner in = new Scanner(System.in); float money =0, old = 0, medicare = 0, outWork = 0, house = 0, total = 0; System.out.print("请输入应发工资:"); money = in.nextFloat(); old = (float) (money * 0.08);// 计算养老保险,税率为8% medicare = (float) (money * 0.02);// 计算医保保险,税率为2% outWork = (float) (money * 0.002);// 计算失业保险,税率为0.2% house = money * 0.12f;// 计算住房公积金,税率为12% total = old + medicare + outWork + house; money = money - total; float gerenTax = geren(money); float income = money - gerenTax; System.out.println("养老保险:" + old + "元"); System.out.println("医疗保险:" + medicare + "元"); System.out.println("失业保险:" + outWork + "元"); System.out.println("住房公积金:" + house + "元"); System.out.println("应缴纳保险总额:" + total + "元"); System.out.println("应交个人所得税:" + gerenTax + "元"); System.out.println("税后实际收入为:" + income + "元"); } //计算个人所得税,按照2022年最新个人所得税税率表计算 public static float geren(float money) { float one = 0, two = 0, three = 0, four = 0, five = 0, six = 0; one = (8000 - 5000) * 0.03f;//第一档满额缴费 two = (17000 - 8000) * 0.1f;//第二档满额缴费 three = (30000 - 17000) * 0.2f;//第三档满额缴费 four = (40000 - 30000) * 0.25f;//第四档满额缴费 five = (60000 - 40000) * 0.3f;//第五档满额缴费 six = (85000 - 60000) * 0.35f;//第六档满额缴费 float tax = 0; if (money <= 5000) tax = 0;//级别1税率 else if (money <= 8000) tax = (money - 5000) * 0.03f;//级别2税率 else if (money <= 17000) tax = (money - 8000) * 0.1f + one;//级别3税率 else if (money <= 30000) tax = (money - 17000) * 0.2f + two + one;//级别4税率 else if (money <= 40000) tax = (money - 30000) * 0.25f + three + two + one;//级别5税率 else if (money <= 60000) tax = (money - 40000) * 0.3f + four + three + two + one;//级别6税率 else if (money <= 85000) tax = (money - 60000) * 0.35f + five + four + three + two + one;//级别7税率 else tax = (money - 85000) * 0.45f + six + five + four + three + two + one;//级别8税率 return tax; } }
二、运行结果
三、粗浅理解
在解决此类问题时,需要先在网上找最新的税率计算利率,找到之后把养老保险,医疗保险,事业保险和住房公积金根据总工资计算的保险金额计算出来。
个人所得税是减去各个保险的金额再计算的,所以减去之后,这里我把个人所得税用到自定方法中去计算,把减去各个保险的工资金额传入自定义方法中计算。
根据最新个人所得税利率计算规律,利用if...else多分支语句,把个所得税f多种情况进行计算,根据传入的数,去对应的分支进行计算,然后返回这个数。
最后把得到的各个值在相应的输出语句中输出。