package exam;
import java.util.*;
class Student implements Comparator<Student> {
private String name;
private int age;
private int chengji;
Student(String name,int age,int chengji){
this.name=name;
this.age=age;
this.chengji=chengji;
}
public int compare(Student s1,Student s2){
int num=new Integer(s1.getChengji()).compareTo(new Integer(s2.getChengji()));
if (num==0)
return new Integer(s1.getAge()).compareTo(new Integer(s2.getAge()));
return num;
}
public int hashCode(){
return name.hashCode()+age*20;
}
public boolean equals(Object obj){
if(!(obj instanceof Student))
throw new ClassCastException("类型不匹配");
Student stu=(Student)obj;
return this.name.equals(stu.name) && this.age==stu.age;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getChengji() {
return chengji;
}
public void setChengji(int chengji) {
this.chengji = chengji;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class TreeSetExam {
public static void sop(Object obj){
System.out.println(obj);
}