Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- Map<String, List<Double>> students = new LinkedHashMap<>();
- Map<String, Double> finalList = new LinkedHashMap<>();
- for (int i = 0; i < n; i++) {
- String name = scanner.nextLine();
- Double grade = Double.parseDouble(scanner.nextLine());
- if (!students.containsKey(name)){
- students.put(name, new ArrayList<>());
- students.get(name).add(grade);
- }else {
- students.get(name).add(grade);
- }
- }
- students.entrySet()
- .forEach(e -> {
- Double average = e.getValue()
- .stream()
- .mapToDouble(x -> x)
- .average()
- .getAsDouble();
- if (average >= 4.50) {
- finalList.put(e.getKey(), average);
- }
- });
- finalList.entrySet()
- .stream()
- .sorted((a,b) -> Double.compare(b.getValue(),
- a.getValue()))
- .forEach(c -> {
- System.out.println(String.format("%s -> %.2f", c.getKey(), c.getValue()));
- });
- }
- }
Add Comment
Please, Sign In to add comment