View difference between Paste ID: NP2CYW3q and jRePX2ZN
SHOW: | | - or go back to the newest paste.
1
import java.time.LocalDate;
2
import java.time.format.DateTimeFormatter;
3
import java.util.ArrayList;
4
import java.util.Scanner;
5
6
public class Task {
7
    public static void main(String[] args) {
8
        Scanner scanner = new Scanner(System.in);
9
        String inputLine = scanner.nextLine();
10
11
        ArrayList<Person> people = new ArrayList<>();
12
13
        while (!"end".equals(inputLine)) {
14
            String[] tokens = inputLine.split(" -> ");
15
            Person person = new Person(tokens[0], tokens[1]);
16
            
17
            people.add(person);
18
            
19
            inputLine = scanner.nextLine();
20
        }
21
22
        people.stream()
23
                .sorted((a, b) -> {
24
                    if (a.getDate().compareTo(b.getDate()) == 0) {
25
                        return -1;
26
                    }
27
                    return a.getDate().compareTo(b.getDate());
28
                })
29
                .limit(5)
30
                .sorted((a, b) -> b.getDate().compareTo(a.getDate()))
31
                .forEach(e -> {
32
                    System.out.println(e.getName());
33
                });
34
35
36
    }
37
38
    
39
}
40
41
class Person {
42
    private String name;
43
    private LocalDate date;
44
45
    public Person(String name, String date) {
46
        this.name = name;
47
        setDate(date);
48
    }
49
50
    public String getName() {
51
        return name;
52
    }
53
54
    public LocalDate getDate() {
55
        return date;
56
    }
57
58
    private void setDate(String date) {
59
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyy");
60
        this.date = LocalDate.parse(date, formatter);
61
    }
62
63
}