这个也是在class Admin中的
private static void avg(List data) {
for (int i = 0; i < data.size(); i++) {
List list = (List) data.get(i);
double sum = 0.0;
int year = 0;
for (int j = 0; j < list.size(); j++) {
Student s = (Student) list.get(j);
sum += s.getChengji();
year = s.getLevel();
}
System.out.println(year + "级平均成绩:" + (sum / list.size()));
}
}
private static List group(List data) {
int oldKey = 0;
List result = new ArrayList();
List list = null;
for (int i = 0; i < data.size(); i++) {
Student s = (Student) data.get(i);
int newKey = s.getLevel();
if (oldKey == newKey) {
if (list == null) {
list = new ArrayList();
}
list.add(s);
} else {
if (list != null) {
result.add(list);
list = null;
}
if (list == null) {
list = new ArrayList();
list.add(s);
}
oldKey = newKey;
}
}
if (list != null) {
result.add(list);
}
return result;
}
private static void sort(List data) {
Collections.sort(data, new Comparator() {
public int compare(Object o1, Object o2) {
Student s1 = (Student) o1;
Student s2 = (Student) o2;
return (int) (s1.getChengji() - s2.getChengji());
}
});
}
private static void show(List data) {
for (int i = 0; i < data.size(); i++) {
System.out.println(data.get(i));
}
}