desislava_topuzakova

06. Strategy Pattern - Main

Oct 16th, 2020
1,889
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. package StrategyPattern_06;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.Scanner;
  6. import java.util.TreeSet;
  7.  
  8. public class Main {
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.  
  12.         int n =  Integer.parseInt(scanner.nextLine());
  13.  
  14.         TreeSet<Person> peopleByNames = new TreeSet<Person>(new PersonNameComparator());
  15.         TreeSet<Person> peopleByAges = new TreeSet<Person>(new PersonAgeComparator());
  16.  
  17.         while (n-- > 0){
  18.             String[] data = scanner.nextLine().split("\\s+");
  19.             Person p = new Person(data[0], Integer.parseInt(data[1]));
  20.             peopleByAges.add(p);
  21.             peopleByNames.add(p);
  22.         }
  23.  
  24.         for (Person person : peopleByNames) {
  25.             System.out.println(person);
  26.         }
  27.  
  28.         for (Person person : peopleByAges) {
  29.             System.out.println(person);
  30.         }
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment