Java实现按分数排名,同分同名次终身学习的重要性
解决⽅案1
/**
* 计算分数排名
* @param allFullScores
*/
public void calculateScoreRank(List<StudentSubjectFullScoreDto> allFullScores){
杨思明敏
Map<Long, StudentSubjectFullScoreDto> stuMap = allFullScores.stream().Map(StudentSubjectFullScoreDto::getStuId, StudentSu bjectFullScoreDto->StudentSubjectFullScoreDto));
//过滤掉不统计的数据,这些数据不参与排名
List<StudentSubjectFullScoreDto> scoreRankList = allFullScores.stream().filter(t -> t.getStatisticsStatu
s()== CommonConst.TYPE_STATISTICS_ENA BLE).List());
//按学⽣单科成绩总分倒序排列
scoreRankList.paringDouble(StudentSubjectFullScoreDto::getSumScore).reverd());
//按分数分组,统计个数
Map<Double, Long> scoreMap = scoreRankList.stream().upingBy(StudentSubjectFullScoreDto::getSumScore, untin g()));
//初始值名次
int rank =1;
double scoreRate =1.0;//此处不需要删除即可
干果机for(int i =0; i < scoreRankList.size(); i++){
//得到相同分数的个数
Long count = ((i).getSumScore());
scoreRate=new BigDecimal(scoreRankList.size()- rank).divide(new BigDecimal(scoreRankList.size()),2, BigDecimal.ROUND_HALF_UP).doubleVa lue();
if(count ==1){
StudentSubjectFullScoreDto copyDto = (i);
StudentSubjectFullScoreDto sourceDto = (StuId());
sourceDto.tScoreRank(rank++);
sourceDto.tScoreRankRate(scoreRate);
}el{
//总分相同,名次相同
for(int j =0; j < count; j++){
StudentSubjectFullScoreDto copyDto = (i+j);关于元旦的古诗
StudentSubjectFullScoreDto sourceDto = (StuId());
sourceDto.tScoreRank(rank);
sourceDto.tScoreRankRate(scoreRate);
}
服务器地址怎么查
//排名还需要按⼈数顺序数他是第⼏个
rank=(int)(rank+count);
行香子问修行门户
//连续n个相同的总分,排名⼀样
i =(int)(i + count -1);
}
}卷发怎么打理
}
解决⽅案2
/**
* 排序:把不同成绩保存map中,最后实体类根据map的key找到排名存⼊实体排名⾥⾯,前端取值。
* @return
*/
public static Map<Double,Integer>rankScore(List<DeductPersonVO> stus){
Map<Double,Integer> map =new HashMap<>();
List<Map.Entry<Double, List<DeductPersonVO>>> list = stus.stream().upingBy(DeductPersonVO::getDeductScore)).entrySet() .stream().sorted((s1, s2)->-Key(), s2.getKey())).List());
int index =1;
for(Map.Entry<Double, List<DeductPersonVO>> entry : list){
map.Key(),index);控辍保学工作方案
System.out.println();
index++;
}
return map;
}
取出值存⼊实体
Map<Double,Integer> rankMap2 =rankScore(personList);
personList.stream().forEach(bean ->{
bean.(DeductScore()));
});