1.输出所有同学的名字及其平均分
2.按平均分的升序排序
3.程序有高的可读性,合理的注解及良好的命名规范
4.程序拥有良好的代码结构,满足面向对象设计,高重用性等要求
结果范例:
王五:55
张三:70
李四:80
public static void shiTi1()
{
List<String> list = Arrays.asList(new String[]{"1,张三,50","2,李四,80","3,王五,40","4,张三,90","5,王五,70"});
TreeMap<String, Integer> scott = new TreeMap<String, Integer>(
/*new Comparator<String>(){
public int compare(String o1, String o2) {
return o2.compareTo(o1);
}
}*/);
TreeMap<Integer, String> last = new TreeMap<Integer, String>();
String found[] = new String[3];
for(int i = 0; i < list.size(); i++)
{
found = list.get(i).split(",");
if(scott.get(found[1]) != null)
{
scott.put(found[1], (scott.get(found[1])+Integer.valueOf(found[2]))/2);
}
else
{
scott.put(found[1],Integer.valueOf(found[2]));
}
}
for(Object m0: scott.entrySet()){
last.put(((Map.Entry<String, Integer>) m0).getValue(),((Map.Entry<String, Integer>) m0).getKey());
}
for(Object m0: last.entrySet()){
System.out.println(((Map.Entry<Integer, String>) m0).getValue()+"---"+((Map.Entry<Integer, String>) m0).getKey());
}
}