Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package JavaProModule.JavaAdvanced.SetsAndMapsLab;
- import java.util.*;
- import java.util.function.DoubleFunction;
- import java.util.stream.Collector;
- import java.util.stream.Collectors;
- public class AcademyGraduation_update_07 {
- public static void main(String[] args) {
- Scanner read = new Scanner(System.in);
- Map<String,List<Double>> studentInfo = new TreeMap<>();
- int loop = Integer.parseInt(read.nextLine());
- int cycle = 0;
- while(cycle < loop){
- // we take name directly from read.nextLine as a String
- String name = read.nextLine();
- List<Double> grades = Arrays.stream(read.nextLine().split("\\s+"))
- .map(Double::parseDouble)
- .collect(Collectors.toList());
- studentInfo.putIfAbsent(name,new ArrayList<>());
- studentInfo.get(name).addAll(grades);
- cycle ++;
- }
- for (Map.Entry<String, List<Double>> myEntry : studentInfo.entrySet()) {
- double avgGrades = 0.0;
- double sumOfAllGrades = 0.0;
- int size = myEntry.getValue().size();
- for (int index = 0; index < size; index++) {
- sumOfAllGrades += myEntry.getValue().get(index);
- }
- avgGrades = sumOfAllGrades / size;
- System.out.println(myEntry.getKey() + " is graduated with " + avgGrades);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement