Advertisement
deyanmalinov

03. Opinion Poll - Java-OOP-Basics

Jun 1st, 2020
737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. package DPM;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Scanner;
  5. public class Main {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.         int lines = Integer.parseInt(scan.nextLine());
  9.         List<Person> people = new ArrayList<>();
  10.         for (int i = 0; i <lines; i++) {
  11.             String[] line = scan.nextLine().split(" ");
  12.             String name = line[0];
  13.             int age = Integer.parseInt(line[1]);
  14.             Person persona = new Person(name, age);
  15.             people.add(persona);
  16.         }
  17.         people.stream()
  18.                 .filter(person -> person.getAge()>30)
  19.                 .sorted((fp, sp) -> fp.getName().compareTo(sp.getName()))
  20.                 .forEach(person -> System.out.println(String
  21.                 .format("%s - %d",person.getName(),person.getAge())));
  22.     }
  23. }
  24. -------------------------------------------------------------------
  25. package DPM;
  26. public class Person {
  27.     private String name;
  28.     private int age;
  29.     public Person(String name, int age){
  30.         this.name=name;
  31.         this.age=age;
  32.     }
  33.     public String getName() {
  34.         return name;
  35.     }
  36.     public void setName(String name) {
  37.         this.name = name;
  38.     }
  39.     public int getAge() {
  40.         return age;
  41.     }
  42.     public void setAge(int age) {
  43.         this.age = age;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement