Advertisement
Kancho

Persons_Age_1

May 14th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. package OpinionPoll;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.ArrayList;
  7. import java.util.Comparator;
  8. import java.util.List;
  9.  
  10. public class Main {
  11. public static void main(String[] args) throws IOException {
  12.  
  13. BufferedReader reader =
  14. new BufferedReader(
  15. new InputStreamReader(
  16. System.in));
  17.  
  18. System.out.println("Number of people ");
  19. int n = Integer.parseInt(reader.readLine());
  20. List<Persons> people = new ArrayList<>();
  21.  
  22. while (n -- > 0) {
  23. System.out.println("Person - age ");
  24. String []data = reader.readLine().split("\\s+");
  25.  
  26. Persons persons = new Persons(data[0], Integer.parseInt(data[1]));
  27. people.add(persons);
  28. }
  29.  
  30. people.stream().filter(persons -> persons.getAge() >= 20)
  31. .sorted(Comparator.comparingInt(Persons::getAge))
  32. .forEach(persons -> {
  33. System.out.println(persons.toString());
  34. });
  35. }
  36. }
  37. package OpinionPoll;
  38.  
  39. public class Persons {
  40.  
  41. private String name;
  42. private int age;
  43.  
  44. public Persons(String name, int age) {
  45. this.name = name;
  46. this.age = age;
  47. }
  48.  
  49. public String getName() {
  50. return this.name;
  51. }
  52.  
  53. public int getAge() {
  54. return this.age;
  55. }
  56.  
  57. @Override
  58. public String toString() {
  59. return String.format("%s - %d", name, age);
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement