过来帮帮忙!急急急!帮我看看为啥不行

weixin_42763119 2018-11-20 10:18:38
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Struct;
import java.util.*;

public class Student {
String id;
String name;
int score;
String code;

public Student(String id, String name, int score, String code) {
this.id = id;
this.name = name;
this.score = score;
this.code = code;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public double getScore() {
return score;
}

public void setScore(int score) {
this.score = score;
}

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

public String toString() {
String s = "";
s += id + ",";
s += name + ',';
s += code + ",";
s += score;
return s;
}

public static void main(String args[]) {
Comparator[] cmps = new Comparator[4];

cmps[0] = new Comparator() {
@Override
public int compare(Object o1, Object o2) {
return ((Student)o1).getId().compareTo(((Student)o2).getId());
}
};
cmps[1] = new Comparator() {
@Override
public int compare(Object o1, Object o2) {
return ((Student)o1).getName().compareTo(((Student)o2).getName());
}
};
cmps[2] = new Comparator() {
@Override
public int compare(Object o1, Object o2) {
return ((Student)o1).getCode().compareTo(((Student)o2).getCode());
}
};
cmps[3] = new Comparator() {
@Override
public int compare(Object o1, Object o2) {
if (((Student)o1).getScore() > ((Student)o2).getScore())
return 1;
else if (((Student)o1).getScore() == ((Student)o2).getScore())
return 0;
else
return -1;
}
};

// String fileName=args[0];
List<Student> students = new ArrayList<>();
String line="";
Scanner sc = new Scanner(System.in);
// try {
// BufferedReader in = new BufferedReader(new FileReader(fileName));
// line = in.readLine();
line = sc.nextLine();
int count = Integer.parseInt(line);
for (int i = 0; i < count; i++) {
// line = in.readLine();
line=sc.nextLine();
String[] l = line.split(",");
String id = l[0];
String name = l[1];
String code = l[2];
int score = Integer.parseInt(l[3]);
Student stu = new Student(id, name, score, code);
students.add(stu);
}
// } catch (IOException e) {
// e.printStackTrace();
// }


while(true) {
line = sc.nextLine();
String[] l = line.split(" ");
int field = Integer.parseInt(l[0]);
if (field == 0)
return;
String flag = l[l.length - 1];
students.sort(cmps[field-1]);
if (flag.equals("A")) {
for (int i = 0; i < students.size(); i++) {
System.out.println(students.get(i));
}
} else if (flag.equals("D")) {
for (int i = students.size() - 1; i >= 0; i--) {
System.out.println(students.get(i));
}
}
System.out.println("");
// field = sc.nextInt();
// if (field == 0)
// break;
}
}
}
...全文
20 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_42763119 2018-11-20
  • 打赏
  • 举报
回复
急急急急急急
weixin_42763119 2018-11-20
  • 打赏
  • 举报
回复
快点来人啊 跪谢
咸哼酒家 2018-11-20
  • 打赏
  • 举报
回复
用你的代码可以正常输出,顺序和图上显示一致

50,526

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧