Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.time.LocalDate;
- import java.time.format.DateTimeFormatter;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Task {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String inputLine = scanner.nextLine();
- ArrayList<Person> people = new ArrayList<>();
- while (!"end".equals(inputLine)) {
- String[] tokens = inputLine.split(" -> ");
- Person person = new Person(tokens[0], tokens[1]);
- people.add(person);
- inputLine = scanner.nextLine();
- }
- people.stream()
- .sorted((a, b) -> {
- if (a.getDate().compareTo(b.getDate()) == 0) {
- return -1;
- }
- return a.getDate().compareTo(b.getDate());
- })
- .limit(5)
- .sorted((a, b) -> b.getDate().compareTo(a.getDate()))
- .forEach(e -> {
- System.out.println(e.getName());
- });
- }
- }
- class Person {
- private String name;
- private LocalDate date;
- public Person(String name, String date) {
- this.name = name;
- setDate(date);
- }
- public String getName() {
- return name;
- }
- public LocalDate getDate() {
- return date;
- }
- private void setDate(String date) {
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyy");
- this.date = LocalDate.parse(date, formatter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement