import java.util.*;
public class Student implements Comparable<Student> {
private String name;
private int age;
public int compareTo(Student s)
{
// Student s=(Student)o;
int num=new Integer(this.age).compareTo(new Integer(s.age));
if (num==0) {
return this.name.compareTo(s.name);
}
return num;
}
public Student(String name,int age)
{
this.name=name;
this.age=age;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public int hashCode()
{
return name.hashCode()+age*37;
}
public boolean equals(Object obj)
{
if (! (obj instanceof Student)) {
throw new ClassCastException("类型不匹配");
}
Student s=(Student)obj;
return this.name.equals(s.name)&&this.age==s.age;
}
}
import java.util.*;
public class com implements Comparator<Student>{
public int compare(Student s1,Student s2)
{
int num=s1.getName().compareTo(s2.getName());
if (num==0) {
return new Integer(s1.getAge()).compareTo(new Integer(s2.getAge()));
}
return num;
}
}