RGAlex

O7. Student Academy - v2.1 for Yordan Kisyov

Mar 28th, 2021
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. package Alex;
  2.  
  3. import java.util.*;
  4.  
  5. public class StudentAcademy {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int n = Integer.parseInt(scanner.nextLine());
  9.         Map<String, List<Double>> studentInformation = new LinkedHashMap<>();
  10.  
  11.         for (int i = 0; i < n; i++) {
  12.             String studentsName = scanner.nextLine();
  13.             double grade = Double.parseDouble(scanner.nextLine());
  14.             studentInformation.putIfAbsent(studentsName, new ArrayList<>());
  15.             studentInformation.get(studentsName).add(grade);
  16.         }
  17.         studentInformation.entrySet().stream().filter(e -> getAverage(e.getValue()) >= 4.50)
  18.                 .sorted((a, b) -> Double.compare(getAverage(b.getValue()), getAverage(a.getValue())))
  19.                 .forEach(e -> System.out.printf("%s -> %.2f%n", e.getKey(), getAverage(e.getValue())));
  20.     }
  21.  
  22.     static double getAverage(List<Double> list) {
  23.         return list.stream().mapToDouble(Double::doubleValue).average().orElseThrow();
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment