eclipse使用Java编写简易版个人所得税计算器
前言
计算个人所得税的缴纳情况。用户从控制台输入税前工资额金额,系统根据用户输入的工作金额计算应缴纳的税额
工资个税的计算公式为:
-
应纳税额 = (工资薪资所得 - 扣除数)* 适用税率 - 速算扣除数
-
全月应纳税所得额 = 月工资薪资所得 - 扣除数
-
2011年9月1日起执行7级超额累进税率:扣除数为3500元
代码实现
具体代码如下:
package day03;
import java.util.Scanner;
public class IncomeTax {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入税前工资金额(¥):");
double total = scan.nextDouble();
if(total < 3500) {
System.out.println("您不需要缴纳个人所得税!");
}else if((total - 3500) <= 4500) {
double tax = (total - 3500) * 3/100;
System.out.println("您应缴纳:"+tax+"元个人所得税");
}else if((total - 3500) <= 4500) {
double tax = (total - 3500) * 10/100 - 105;
System.out.println("您应缴纳:"+tax+"元个人所得税");
}else if((total - 3500) <= 9000) {
double tax = (total - 3500) * 20/100 - 555;
System.out.println("您应缴纳:"+tax+"元个人所得税");
}else if((total - 3500) <= 35000) {
double tax = (total - 3500) * 25/100 - 1005;
System.out.println("您应缴纳:"+tax+"元个人所得税");
}else if((total - 3500) <= 55000) {
double tax = (total - 3500) * 30/100 - 2755;
System.out.println("您应缴纳:"+tax+"元个人所得税");
}else if((total - 3500) <= 80000) {
double tax = (total - 3500) * 35/100 - 5505;
System.out.println("您应缴纳:"+tax+"元个人所得税");
}else {
double tax = (total - 3500) * 45/100 - 13505;
System.out.println("您应缴纳:"+tax+"元个人所得税");
}
}
}
代码优化:
package day03;
import java.util.Scanner;
public class IncomeTax {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入税前工资金额(¥):");
double total = scan.nextDouble();
double taxIncome = total - 3500;
double tax = 0.0;
if(total < 3500) {
tax = 0.0;
}else if(taxIncome <= 4500) {
tax = taxIncome * 3/100;
}else if(taxIncome <= 4500) {
tax = taxIncome * 10/100 - 105;
}else if(taxIncome <= 9000) {
tax = taxIncome * 20/100 - 555;
}else if(taxIncome <= 35000) {
tax = taxIncome * 25/100 - 1005;
}else if(taxIncome <= 55000) {
tax = taxIncome * 30/100 - 2755;
}else if(taxIncome <= 80000) {
tax = taxIncome * 35/100 - 5505;
}else {
tax = taxIncome * 45/100 - 13505;
}
System.out.println("您应缴纳:"+tax+"元个人所得税");
}
}