计算税后工资
计算方式:先扣除公积金和养老金,扣除后工资作为个税征收的基数扣个税
公积金:8%
养老金:11%
个税:起征点3500;3500-5000:扣5%;5000-10000扣10%;10000-15000扣15%;15000以上扣20%
要求:具备一定灵活性,国家政策改变,仍可实现正确计算
public class Exercise{ //p1:3500;p2:5000;p3:10000;p4:15000 //tax1:公积金8%;tax2:养老金11%; //tax3:5%;tax4:10%;tax:15%;tax6:20% public double afterSalary(double salary,int p1,int p2,int p3,int p4,double tax1,double tax2,double tax3,double tax4,double tax5,double tax6){ //计算个税基数 salary=salary-salary*tax1-salary*tax2 //计算的过程中要与每个阶段进行比较,所以将原数记录下来 afterSalary=salary; //如果工资在15000以上 if(salary>=p4){ afterSalary=salary-(salary-p4)*tax6-(p4-p3)*tax5-(p3-p2)*tax4-(p2-p1)*tax3; }
//工资在10000-15000 else if(salary>=p3){ afterSalary=salary-(psalary-p3)*tax5-(p3-p2)*tax4-(p2-p1)*tax3; }
//工资在5000-10000 else if(salary>=p2){ afterSalary=salary-(salary-p2)*tax4-(p2-p1)*tax3; }
//工资在3500-5000 else if(salary>=p1){ afterSalary=salary-(salary-p1)*tax3; } }
//调用计算税后工资的方法 public static void main(String[] args){
//实例化 Exercise1 ex=new Exercise1();
//输入获得工资金额 sout("请输入工资金额:") int salary=sc.next();
//调用方法 double after=ex.afterSalary(salary,3500,5000,10000,15000,0.08,0.11,0.05,0.1,0.15,0.2) sout("税后工资是:"+after); } }