import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
class Student implements Comparable{
private String xh; //学号
private String xm; //姓名
private double cj; //成绩
public String getXh() {
return xh;
}
public void setXh(String xh) {
this.xh = xh;
}
public String getXm() {
return xm;
}
public void setXm(String xm) {
this.xm = xm;
}
public double getCj() {
return cj;
}
public void setCj(double cj) {
this.cj = cj;
}
public int compareTo(Student other) {
if (cjreturn -1 ;
if (cj>other.cj)
return 1 ;
return 0 ;
}
}
public class StudentComp{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Listlist = new ArrayList ();
byte b = 57;
String isjs = "";
int i = 1;
while(!"#".equals(isjs)){
Student stu = new Student();
System.out.println("请输入第"+(i++)+"个学生信息:");
System.out.print("学号:");
stu.setXh(scanner.next());
System.out.print("姓名:");
stu.setXm(scanner.next());
System.out.print("成绩:");
stu.setCj(scanner.nextDouble());
list.add(stu);
System.out.print("是否结束?(输入“#”结束,输入其他任意字符继续)");
isjs = scanner.next();
}
Student[] students = (Student[])list.toArray(new Student[list.size()]);
// for(int j=0;j// students[j] = list.get(j);
// }
Arrays.sort(students);
for(Student s:students){
System.out.println("学号:"+s.getXh()+" 姓名:"+s.getXm()+" 成绩:"+s.getCj());
}
}
}