desislava_topuzakova

Opinion Poll - Main

Feb 21st, 2021
1,110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. package OpinionPoll_03;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Comparator;
  5. import java.util.List;
  6. import java.util.Scanner;
  7. import java.util.stream.Collectors;
  8.  
  9. public class Main {
  10.     public static void main(String[] args) {
  11.         Scanner scanner = new Scanner(System.in);
  12.         int n = Integer.parseInt(scanner.nextLine());
  13.         List<Person> people = new ArrayList<>();
  14.         for (int i = 1; i <= n; i++) {
  15.             String personalData = scanner.nextLine();// name and age
  16.             //"Pesho 12" -> ["Pesho", "12"]
  17.             String name = personalData.split("\\s+")[0];
  18.             int age = Integer.parseInt(personalData.split("\\s+")[1]);
  19.             Person person = new Person(name, age);
  20.             people.add(person);
  21.  
  22.  
  23.         }
  24.  
  25.         List<Person> filteredList = people.stream().filter(p -> p.getAge() > 30).collect(Collectors.toList());
  26.         filteredList.sort(Comparator.comparing(Person::getName).thenComparing(Person::getAge));
  27.  
  28.         for (Person person : filteredList ) {
  29.             System.out.println(person);
  30.         }
  31.  
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment