Tech Module Java // 07. Student Academy
Здравейте може ли помощ за 07. Student Academy https://pastebin.com/0jgDAg00 накрая немога да го измисля как да ги сортирам descending по average grade?
1.Student Academy
Write a program, which keeps information about students and their grades.
You will receive n pair of rows. First you will receive the student's name, after that you will receive his grade. Check if student already exists, and if not, add him. Keep track of all grades for each student.
When you finish reading data, keep students with average grade higher or equal to 4.50. Order filtered students by average grade in descending.
Print the students and their average grade in format:
"{name} –> {averageGrade}"
Format the average grade to the 2nd decimal place.
Examples
Input |
Output |
|
Input |
Output |
5 John 5.5 John 4.5 Alice 6 Alice 3 George 5 |
John -> 5.00 George -> 5.00 Alice -> 4.50 |
|
5 Amanda 3.5 Amanda 4 Rob 5.5 Christian 5 Robert 6 |
Robert -> 6.00 Rob -> 5.50 Christian -> 5.00 |
Демек "Pair<>" взима key и му слага съответният averageGrade,като value ?
students.entrySet().stream()
.map(e -> {
Double averageGrade = e.getValue().stream().mapToDouble(x -> x).average().getAsDouble();
return new Pair<>(e.getKey(), averageGrade);