牛客-Java计算个人所得税

 思路:

1.新建三个employee对象。

2.通过有参构造的方式新建employee对象。

3.通过List集合的add方法,将employee对象放入集合中。

4.过遍历集合来对集合中元素进行操作,首先我们定义double类型的个人所得税变量以及应纳税额变量。

5.使用if,if else语句,对每个工资等级进行划分并按照表格中给出的计算方法进行计算。

6.因为逻辑在集合遍历中实现,所以在输出时应该首先获得当前集合中的employee对象,使用getName()方法得到当前对象的姓名属性。

import java.util.*;
 
public class Main {
     
    public static void main(String[] args) {
        List<Employee> employees = new ArrayList<>();
        Employee e1 = new Employee("小明",2500);
        Employee e2 = new Employee("小军",8000);
        Employee e3 = new Employee("小红",100000);
        employees.add(e1) ;
        employees.add(e2) ;
        employees.add(e3) ;
        Iterator it = employees.iterator();
        while(it.hasNext()){
            Employee e4 = (Employee) it.next() ;
            double num = e4.getSalary() - 3500.00;
            double sax = 0.0 ;
            if(num < 0 ){
            }else if(num <= 1500){
                sax = num * 0.03 - 0 ;
            }else if(num <= 4500){
                sax = num * 0.1 - 105 ;
            }else if(num <= 9000){
                sax = num * 0.2 - 555 ;
            }else if(num <= 35000){
                sax = num * 0.25 - 1005 ;
            }else if(num <= 55000){
                sax = num * 0.3 - 2755 ;
            }else if(num <= 80000){
                sax = num * 0.35 - 5505 ;
            }else if(num > 80000){
                sax = num * 0.45 - 13505 ;
            }
            System.out.println(e4.getName()+"应该缴纳的个人所得税是:"+sax);
        }
 
    }
}
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;
    }
}

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ws_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值