-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJ05007.java
57 lines (51 loc) · 1.77 KB
/
J05007.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
class Officer implements Comparable<Officer> {
public static int NUM_OFFICER = 1;
private String id, name, gender, birthDate, address, taxcode, date;
public Officer(String name, String gender, String birthDate, String address, String taxcode, String date) {
this.id = String.format("%05d", NUM_OFFICER++);
this.name = name;
this.gender = gender;
this.birthDate = birthDate;
this.address = address;
this.taxcode = taxcode;
this.date = date;
}
public Date getbirthDate() {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
try {
return sdf.parse(birthDate);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
public String toString() {
return id + " " + name + " " + gender + " " + birthDate + " " + address + " " + taxcode + " " + date;
}
@Override
public int compareTo(Officer o) {
if (this.getbirthDate().compareTo(o.getbirthDate()) > 0) {
return 1;
} else if (this.getbirthDate().compareTo(o.getbirthDate()) < 0) {
return -1;
} else {
return 0;
}
}
}
public class J05007 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = Integer.parseInt(sc.nextLine());
List<Officer> list = new ArrayList<>();
for (int i = 0; i < t; i++) {
list.add(new Officer(sc.nextLine(), sc.nextLine(), sc.nextLine(), sc.nextLine(), sc.nextLine(), sc.nextLine()));
}
Collections.sort(list);
for (Officer officer : list) {
System.out.println(officer);
}
}
}