题解 | #类型转换#

编写个人所得税计算程序

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

import java.util.*;

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

        //write your code here......
        Employee employee1 = new Employee("小明", 2500);
        Employee employee2 = new Employee("小军", 8000);
        Employee employee3 = new Employee("小红", 100000);

        employees.add(employee1);
        employees.add(employee2);
        employees.add(employee3);

        for (Employee ee : employees) {
            System.out.printf("%s应该缴纳的个人所得税是:%.1f\n",ee.getName(),ee.getNewSalary(ee.getSalary()));
        }

    }
}

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;
    }

    public double getNewSalary(double salary) {
        double newSalary = salary - 3500;
        if (newSalary <= 0) {
            return 0;
        } else if (newSalary <= 1500) {
            return (newSalary * 0.03);
        } else if (newSalary <= 4500) {
            return (newSalary * 0.1) - 105;
        } else if (newSalary <= 9000) {
            return (newSalary * 0.2) - 555;
        } else if (newSalary <= 35000) {
            return (newSalary * 0.25) - 1005;
        } else if (newSalary <= 55000) {
            return (newSalary * 0.3) - 2755;
        } else if (newSalary <= 80000) {
            return (newSalary * 0.35) - 5505;
        } else {
            return (newSalary * 0.45) - 13505;
        }
    }
}
全部评论

相关推荐

牛客868257804号:九个中铁八个中建
点赞 评论 收藏
分享
牛客154160166号:9月底还给我发短信,好奇怪,我24届的
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务