Advertisement
SotirovG

AcademyGraduation_07/JavaAdvanced

Sep 26th, 2021
952
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. package JavaProModule.JavaAdvanced.SetsAndMapsLab;
  2.  
  3. import java.util.*;
  4. import java.util.function.DoubleFunction;
  5. import java.util.stream.Collector;
  6. import java.util.stream.Collectors;
  7.  
  8. public class AcademyGraduation_update_07 {
  9.     public static void main(String[] args) {
  10.         Scanner read = new Scanner(System.in);
  11.         Map<String,List<Double>> studentInfo = new TreeMap<>();
  12.  
  13.         int loop = Integer.parseInt(read.nextLine());
  14.         int cycle = 0;
  15.  
  16.         while(cycle < loop){
  17.             // we take name directly from read.nextLine as a String
  18.  
  19.             String name = read.nextLine();
  20.             List<Double> grades = Arrays.stream(read.nextLine().split("\\s+"))
  21.                     .map(Double::parseDouble)
  22.                     .collect(Collectors.toList());
  23.  
  24.             studentInfo.putIfAbsent(name,new ArrayList<>());
  25.             studentInfo.get(name).addAll(grades);
  26.  
  27.  
  28.             cycle ++;
  29.         }
  30.         for (Map.Entry<String, List<Double>> myEntry : studentInfo.entrySet()) {
  31.             double avgGrades = 0.0;
  32.             double sumOfAllGrades = 0.0;
  33.             int size = myEntry.getValue().size();
  34.             for (int index = 0; index < size; index++) {
  35.                 sumOfAllGrades += myEntry.getValue().get(index);
  36.             }
  37.             avgGrades = sumOfAllGrades / size;
  38.             System.out.println(myEntry.getKey() + " is graduated with " + avgGrades);
  39.         }
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.     }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement