// 定义Map集合
Map<String, ClassRoom> map = new HashMap<String, ClassRoom>();
for (int i = 0; i < l1.size(); i++) {
map.put(l1.get(i).getNo(), c1);
}
for (int i = 0; i < l2.size(); i++) {
map.put(l2.get(i).getNo(), c2);
}
// 规定格式化
DecimalFormat df = new DecimalFormat("######0.00");
// 遍历map
Set keySet = map.keySet();
Iterator it = keySet.iterator();
while (it.hasNext()) {
Double sum = 0.0;
Double avg = 0.0;
String key = (String) it.next();
ClassRoom value = (ClassRoom) map.get(key);
// 遍历集合求总成绩与平均成绩
for (Student ss : value.getClassRoom()) {
sum += ss.getScore();
avg = sum / value.getClassRoom().size();
}
System.out.println(key + "班总成绩为" + df.format(sum) + "分");
System.out.println(key + "班平均成绩为" + df.format(avg) + "分");
}