题解 | 编写个人所得税计算程序
编写个人所得税计算程序
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; } }