把业绩最低的两个员工删除

网友投稿 978 2022-10-27

把业绩最低的两个员工删除

把业绩最低的两个员工删除

package com.xinzhi.api;import java.util.Objects;public class Staff { private String name; private int age; private int score; public Staff() { } public Staff(String name, int age, int score) { this.name = name; this.age = age; this.score = score; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public int getScore() { return score; } public void setScore(int score) { this.score = score; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Staff staff = (Staff) o; return age == staff.age && score == staff.score && Objects.equals(name, staff.name); } @Override public int hashCode() { return Objects.hash(name, age, score); } @Override public String toString() { return "Staff{" + "name='" + name + '\'' + ", age=" + age + ", score=" + score + '}'; }}

package com.xinzhi.list;import java.util.ArrayList;import java.util.Comparator;//把业绩最不好的两个员工给删了public class Test01 { public static void main(String[] args) { ArrayList staffs = new ArrayList<>(); Staff staff1 = new Staff("张三", 18, 65); Staff staff2 = new Staff("李四", 20, 80); Staff staff3 = new Staff("王五", 32, 70); Staff staff4 = new Staff("赵六", 45, 60); staffs.add(staff1); staffs.add(staff2); staffs.add(staff3); staffs.add(staff4); System.out.println(staffs); //剩下的打不出来了 staffs.sort(new Comparator() { @Override public int compare(Staff o1, Staff o2) { return o2.getScore()-o1.getScore(); } }); System.out.println(staffs); staffs.remove(staffs.size() - 1); staffs.remove(staffs.size() - 1); System.out.println(staffs); }}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:一个基于unity3d的游戏完全开发框架
下一篇:antnet:一个go(Golang)游戏服务器网络框架
相关文章

 发表评论

暂时没有评论,来抢沙发吧~