Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Ex07_StudentsAcademy {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, List<Double>> studentsGrades = new LinkedHashMap<>();
- int countStudents = Integer.parseInt(scanner.nextLine());
- for (int i = 0; i < countStudents; i++) {
- String studentName = scanner.next();
- double score = scanner.nextDouble();
- studentsGrades.putIfAbsent(studentName, new ArrayList<>());
- studentsGrades.get(studentName).add(score);
- }
- Map<String, Double> toPrint = new LinkedHashMap<>();
- studentsGrades
- .entrySet()
- .forEach(student -> {
- double result = student.getValue().stream().mapToDouble(Double::doubleValue).average().getAsDouble();
- if ( result >=4.5){
- toPrint.put(student.getKey(),result);
- }
- });
- toPrint
- .entrySet()
- .stream()
- .sorted((f, s) -> Double.compare(s.getValue(),f.getValue()))
- .forEach(student -> System.out.println(String.format("%s -> %.2f",student.getKey(), student.getValue())));
- /* studentsGrades.
- entrySet()
- .stream()
- .filter(student -> student.getValue()
- .stream()
- .mapToDouble(Double::doubleValue)
- .average().getAsDouble() >= 4.5)
- .sorted((student1, student2) -> {
- double first = student1.getValue().stream().mapToDouble(Double::doubleValue).average().getAsDouble();
- double second = student2.getValue().stream().mapToDouble(Double::doubleValue).average().getAsDouble();
- return Double.compare(second, first);
- })
- .forEach(student -> System.out.println(String.format("%s -> %.2f",
- student.getKey(),
- student.getValue().stream().mapToDouble(Double::doubleValue).average().getAsDouble()
- )));
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement