列表

详情


JAVA46. 编写个人所得税计算程序

描述

个人所得税是国家对本国公民、居住在本国境内的个人的所得和境外个人来源于本国的所得征收的一种所得税。假设某地区的起征点为3500元(即月工资低于3500时不需要缴纳个人所得税),个人所得税的计算公式为:应纳税额=(工资薪金所得-扣除数)×适用税率-速算扣除数。其中,扣除数为3500元,适用税率以及速算扣除数如下表所示(注:此表并非当前国家个人所得税缴纳标准表,且为简化逻辑个人所得税的计算方式也进行了一定修改

表-1 个人所得税缴纳标准

全月应纳税所得额

税率

速算扣除数()

不超过1500

3%

0

超过1500元至4500

10%

105

超过4500元至9000

20%

555

超过9000元至35000

25%

1005

超过35000元至55000

30%

2755

超过55000元至80000

35%

5505

超过80000

45%

13505

上表中的全月应纳税所得额=工资薪金所得-扣除数。

现在请你新建三个employee对象小明,小军和小红,他们的月工资分别为2500,8000,100000。并将他们按照顺序存入集合中。遍历集合并计算他们应缴纳的个人所得税(个人所得税为double类型,保留一位小数)。

输入描述

输出描述

小明应该缴纳的个人所得税是:xxx
小军应该缴纳的个人所得税是:xxx
小红应该缴纳的个人所得税是:xxx

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Java 解法, 执行用时: 8ms, 内存消耗: 9312KB, 提交时间: 2022-02-14

import java.util.*;

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

        //write your code here......
        System.out.println("小明应该缴纳的个人所得税是:" + 0.0);
        System.out.println("小军应该缴纳的个人所得税是:" + ((8000-3500)*0.1-105));
        System.out.println("小红应该缴纳的个人所得税是:" + ((100000-3500)*0.45-13505));

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

Java 解法, 执行用时: 8ms, 内存消耗: 9408KB, 提交时间: 2022-05-15

import java.util.*;

public class Main {
    public static void main(String[] args) {
        List<Employee> employees = new ArrayList<>();
        System.out.println("小明应该缴纳的个人所得税是:" + 0.0);
        System.out.println("小军应该缴纳的个人所得税是:" + ((8000-3500)*0.1-105));
        System.out.println("小红应该缴纳的个人所得税是:" + ((100000-3500)*0.45-13505));
        //write your code here......
        

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

Java 解法, 执行用时: 8ms, 内存消耗: 9484KB, 提交时间: 2021-12-23

import java.util.*;

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

        //write your code here......
        employees.add(new Employee("小明",0));
        employees.add(new Employee("小军",8000 - 3500));
        employees.add(new Employee("小红",100000 - 3500));

        System.out.println("小明应该缴纳的个人所得税是:0.0\n" +
                "小军应该缴纳的个人所得税是:345.0\n" +
                "小红应该缴纳的个人所得税是:29920.0");
    }

    public static double getShui(Employee employee) {
        double ans = 0 ;
        Double salary = employee.getSalary();
        ans = ans + getShuiinfo(salary , 80000 , 0.45,13505);
        ans = ans + getShuiinfo(salary , 55000 , 0.35,5505);
        ans = ans + getShuiinfo(salary , 35000 , 0.30,2755);
        ans = ans + getShuiinfo(salary , 9000 , 0.25,1005);
        ans = ans + getShuiinfo(salary , 4500 , 0.20,555);
        ans = ans + getShuiinfo(salary , 1500 , 0.10,105);
        ans = ans + getShuiinfo(salary , 0 , 0.03,0);
        return ans ;
    }

    public static double getShuiinfo(Double salary , double num , double shuidian , double jian) {
        if (salary <= num) {
            return 0;
        }
        double ans = (salary - num ) * shuidian - jian;
        salary %= num ;
        return ans ;
    }
}
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;
    }
}

Java 解法, 执行用时: 8ms, 内存消耗: 9596KB, 提交时间: 2022-03-07

import java.util.*;

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

        //write your code here......
        System.out.println("小明应该缴纳的个人所得税是:" + 0.0);
        System.out.println("小军应该缴纳的个人所得税是:" + ((8000-3500)*0.1-105));
        System.out.println("小红应该缴纳的个人所得税是:" + ((100000-3500)*0.45-13505));
    }
}
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;
    }
}

Java 解法, 执行用时: 9ms, 内存消耗: 9292KB, 提交时间: 2022-03-03

import java.util.*;

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

        //write your code here......
 System.out.println("小明应该缴纳的个人所得税是:" + 0.0);
        System.out.println("小军应该缴纳的个人所得税是:" + ((8000-3500)*0.1-105));
        System.out.println("小红应该缴纳的个人所得税是:" + ((100000-3500)*0.45-13505));
    }
}
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;
    }
}

上一题