public class Seller implements Comparable<Seller> {
private String no;
private String name;
private int sales1;
private int sales2;
private int sales3;
private int sales4;
public Seller(String no, String name, int sales1, int sales2, int sales3, int sales4) {
this.no = no;
this.name = name;
this.sales1 = sales1;
this.sales2 = sales2;
this.sales3 = sales3;
this.sales4 = sales4;
}
public int getAssemble(){
return this.sales1+this.sales2+this.sales3+this.sales4;
}
@Override
public String toString() {
return this.no+" "+this.name+" "+this.getAssemble()+" "+this.dengJi();
}
public String dengJi(){
if (this.getAssemble()>=10000){
return "优秀";
}else if(7000<=this.getAssemble() && 9999>=this.getAssemble()){
return "良好";
}else if(4000<=this.getAssemble() && 6999>=this.getAssemble()){
return "及格";
}else {
return "不及格";
}
}
@Override
public int compareTo(Seller o) {
if(this.getAssemble() == o.getAssemble()){
return this.no.compareTo(o.no);
}
return this.getAssemble()-o.getAssemble()>0?-1:1;
}
}
import java.util.*;
public class Main {
public static void main(String[] args) {
Seller s1 = new Seller("s011","撒贝贝",2195,1700,2020,3875);
Seller s2 = new Seller("s001","康辉辉",2580,2742,3000,2498);
Seller s3 = new Seller("s015","尼格格",1802,2731,1420,758);
Seller s4 = new Seller("s008","朱权权",3472,898,2164,3256);
TreeSet<Seller> ts = new TreeSet<>();
ts.add(s1);
ts.add(s2);
ts.add(s3);
ts.add(s4);
for (Seller t : ts) {
System.out.println(t);
}
}
}```