Java, 7. Student Academy
Условия:
https://softuni.bg/trainings/resources/officedocument/56688/exercise-problem-descriptions-java-fundamentals-january-2021/3212
package JavaFundamentals;
import java.util.*;
public class StudentAcademy {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = Integer.parseInt(scan.nextLine());
Map<String, List<Double>> gradesOfStudents = new HashMap<>();
String person;
double grade;
for (int i = 0; i < n; i++) {
person = scan.nextLine();
grade = Double.parseDouble(scan.nextLine());
if (!gradesOfStudents.containsKey(person)) {
gradesOfStudents.put(person, new ArrayList<>());
}
gradesOfStudents.get(person).add(grade);
}
double average;
Map<String, Double> averageGrades = new HashMap<>();
for (Map.Entry<String, List<Double>> entry : gradesOfStudents.entrySet()) {
average = 0;
for (int i = 0; i < entry.getValue().size(); i++) {
average = average + entry.getValue().get(i);
}
average = average / entry.getValue().size();
if (average >= 4.5) {
averageGrades.put(entry.getKey(), average);
}
}
averageGrades.entrySet().stream().sorted((d1, d2) -> Double.compare(d1.getValue().compareTo(d2.getValue()))).forEach(name -> {
System.out.print(name.getKey() + " -> ");
System.out.printf("%.2f %n", name.getValue());
});
}
}
Грешката е в ето този ред:
.sorted((d1, d2) -> Double.compare(d1.getValue().compareTo(d2.getValue())))