-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ05005.java
More file actions
80 lines (68 loc) · 2.21 KB
/
J05005.java
File metadata and controls
80 lines (68 loc) · 2.21 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//src/J05005.java
import java.util.*;
public class J05005 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
ArrayList<SinhVien> a = new ArrayList<>();
for (int i = 1; i <= t; i++) {
sc.nextLine();
SinhVien x = new SinhVien(i, sc.nextLine(), sc.nextLine(), sc.nextLine(), sc.nextDouble());
a.add(x);
}
Collections.sort(a, new Comparator<SinhVien>() {
@Override
public int compare(SinhVien o1, SinhVien o2) {
if (o1.getGpa() > o2.getGpa()) {
return -1;
} else {
return 1;
}
}
});
for (SinhVien x : a) {
System.out.println(x);
}
}
}
//src/SinhVien.java
class SinhVien {
private String msv;
private String name;
private String lop;
private String ngaySinh;
private double gpa;
public SinhVien(int msv, String name, String lop, String ngaySinh, double gpa) {
this.msv = "B20DCCN" + String.format("%03d", msv);
this.name = name;
this.lop = lop;
this.ngaySinh = ngaySinh;
this.gpa = gpa;
}
public double getGpa() {
return gpa;
}
private String chuanHoaTen(String x) {
StringBuilder sb = new StringBuilder("");
String[] a = x.trim().split("\\s+");
for (String res : a) {
sb.append(Character.toUpperCase(res.charAt(0)));
for (int i = 1; i < res.length(); i++) {
sb.append(Character.toLowerCase(res.charAt(i)));
}
sb.append(" ");
}
return sb.toString().trim();
}
public String toString() {
StringBuilder sb = new StringBuilder(this.ngaySinh);
if (sb.charAt(2) != '/') {
sb.insert(0, "0");
}
if (sb.charAt(5) != '/') {
sb.insert(3, "0");
}
String tmp = chuanHoaTen(this.name);
return this.msv + " " + tmp + " " + this.lop + " " + sb.toString() + " " + String.format("%.2f", this.gpa);
}
}