public class TestIo {
public static void main(String[]args) throws Exception {
Set<Student> stus = StudentInfoTool.getStudents();
StudentInfoTool.write2File(stus);
}
}
class Student implements Comparable<Student>
{
private String name ;
private int cn;
private int ma;
private int en;
private int sum;
Student(String name ,int cn,int ma,int en) {
this.name = name;
this.cn = cn;
this.ma = ma;
this.en = en;
this.sum = cn+ma+en;
}
public String toString() {
return "Student["+name+","+cn+","+ma+","+en+"]";
}
public int hashCode() {
return name.hashCode()+sum*78;
}
public int compareTo(Student s) {
int num = new Integer(this.sum).compareTo(new Integer(s.sum));
if(num == 0)
return this.name.compareTo(s.name);
return num;
}
public String getName() {
return this.name;
}
public int getSum() {
return this.sum;
}
public boolean equals (Object obj) {
if(!(obj instanceof Student))
throw new ClassCastException("类型不匹配");
Student s = (Student) obj;
class StudentInfoTool {
public static Set<Student> getStudents() throws Exception {
BufferedReader bufr = new BufferedReader(new InputStreamReader(System.in));
String line = null;