如有帮助,请采纳
public class Student {
private String sno;
private String sname;
private Double score;
public void setData(String sno,String sname,Double score){
this.sno = sno;
this.sname = sname;
this.score = score;
}
public void display(){
System.out.println("学号:" + sno + " 姓名:" + sname + " 成绩:" + score);
}
public Double getScore(){
return this.score;
}
}
public class Manage {
private List<Student> studentList = new ArrayList<>();
public void input(){
Scanner scan = new Scanner(System.in);
System.out.print("请输入录入学员的人数:");
int c = 0;
if( scan.hasNextInt()){
c = scan.nextInt();
}else {
return;
}
for( int i = 0 ; i < c ; i++) {
String sno = "";
String sname = "";
Double score = 0D;
System.out.print("请输入学号:");
if( scan.hasNext()){
sno = scan.next();
}
System.out.print("请输入姓名:");
if( scan.hasNext()){
sname = scan.next();
}
System.out.print("请输入成绩:");
if( scan.hasNextDouble()){
score = scan.nextDouble();
}
Student student = new Student();
student.setData(sno,sname,score);
studentList.add(student);
System.out.println("-----------------------------");
}
//scan.close();
}
public void output(){
for( Student student : studentList) {
student.display();
System.out.println("-----------------------------");
}
}
public void sort(){
Collections.sort(studentList,new Comparator<Student>() {
@Override
public int compare(Student o1, Student o2) {
return o1.getScore().compareTo(o2.getScore());
}
});
output();
}
public static void main(String[] args) {
Manage manage = new Manage();
String operation = "";
Scanner scan = new Scanner(System.in);
System.out.println("请输入操作类型A:录入学员基本信息 B:输出信息 C:排序 E:退出系统");
while (scan.hasNext()){
operation = scan.next().trim().toUpperCase(Locale.ROOT);
if( operation.equals("A")) {
manage.input();
System.out.println("数据录入完成");
}
if( operation.equals("B")) {
manage.output();
System.out.println("数据输出完成");
}
if( operation.equals("C")) {
manage.sort();
System.out.println("排序完成");
}
if( operation.equals("E")) {
System.out.println("系统退出");
break;
}
System.out.println("请输入操作类型A:录入学员基本信息 B:输出信息 C:排序 E:退出系统");
}
scan.close();
}
}