题解 | 编写个人所得税计算程序

编写个人所得税计算程序

https://www.nowcoder.com/practice/7a1f759199654f9abc69a3ef2f54d451

import java.util.*;

public class Main {
    public static void main(String[] args) {
        List<Employee> employees = new ArrayList<>();

        employees.add(new Employee("小明", 2500));
        employees.add(new Employee("小军", 8000));
        employees.add(new Employee("小红", 100000));

        //write your code here......
        employees.forEach(e -> {
            System.out.println(e.getName() + "应该缴纳的个人所得税是:" + String.format("%.1f", getTax(e)));
        });
    }

    public static double getTax(Employee emp) {
        double tax = 0.0;
        if (emp.getSalary() < 3500) {
            return tax;
        } else if (emp.getSalary() <= 3500 + 1500) {
            tax = (emp.getSalary() - 3500) * 0.03 - 0;
        } else if (emp.getSalary() <= 3500 + 4500) {
            tax = (emp.getSalary() - 3500) * 0.1 - 105;
        } else if (emp.getSalary() <= 3500 + 9000) {
            tax = (emp.getSalary() - 3500) * 0.2 - 555;
        } else if (emp.getSalary() <= 3500 + 35000) {
            tax = (emp.getSalary() - 3500) * 0.25 - 1005;
        } else if (emp.getSalary() <= 3500 + 55000) {
            tax = (emp.getSalary() - 3500) * 0.3 - 2755;
        } else if (emp.getSalary() <= 3500 + 80000) {
            tax = (emp.getSalary() - 3500) * 0.35 - 5505;
        } else{
            tax = (emp.getSalary() - 3500) * 0.45 - 13505;
        }
        return tax;
    }
}
class Employee{
    private String name;
    private double salary;
    public Employee(String name, double salary) {
        this.name = name;
        this.salary = salary;
    }
    public String getName() {
        return name;
    }

    public double getSalary() {
        return salary;
    }
}

全部评论

相关推荐

程序员小假:人才
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务