RGAlex

O8. Academy Graduation

May 27th, 2021
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. import java.util.*;
  2. import java.util.stream.Collectors;
  3. import java.util.stream.IntStream;
  4.  
  5. public class AcademyGraduation {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         Scanner scan = new Scanner(System.in);
  10.         int numberOfStudents = Integer.parseInt(scan.nextLine());
  11.         Map<String, List<Double>> graduationList = new TreeMap<>();
  12.  
  13.         IntStream.range(0, numberOfStudents).mapToObj(i -> scan.nextLine())
  14.                 .forEach(name -> graduationList.put(name, Arrays.stream(scan.nextLine().split("\\s+"))
  15.                 .map(Double::parseDouble).collect(Collectors.toList())));
  16.  
  17.         graduationList.forEach((k, v) -> System.out.printf("%s is graduated with %s%n", k, getAverage(v)));
  18.     }
  19.  
  20.     private static Double getAverage(List<Double> value) {
  21.         double average = 0.0;
  22.         for (Double aDouble : value) {
  23.             average += aDouble;
  24.         }
  25.         return average / value.size();
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment