-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJ05005.java
79 lines (71 loc) · 2.25 KB
/
J05005.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
class Student3 implements Comparable<Student3> {
private static int NUM_STUDENT = 1;
private String id, name;
private String className;
private String birthday;
private float GPA;
public Student3(String name, String className, String birthday, float GPA) {
this.id = "B20DCCN" + String.format("%03d", NUM_STUDENT++);
this.name = name;
this.className = className;
this.birthday = birthday;
this.GPA = GPA;
}
public String formatName(String s) {
String[] a = s.split(" ");
String kq = "";
for (int i = 0; i < a.length; i++) {
if (a[i].length() > 0) {
kq += a[i].substring(0, 1).toUpperCase() + a[i].substring(1).toLowerCase() + " ";
}
}
return kq.trim();
}
public String formatBirthday(String s) {
String[] a = s.split("/");
String kq = "";
if (a[0].length() == 1) {
a[0] = "0" + a[0];
}
if (a[1].length() == 1) {
a[1] = "0" + a[1];
}
kq = a[0] + "/" + a[1] + "/" + a[2];
return kq;
}
public int compareTo(Student3 o) {
if (this.GPA < o.GPA) {
return 1;
} else if (this.GPA > o.GPA) {
return -1;
} else {
return this.name.compareTo(o.name);
}
}
public String toString() {
return id + " " + formatName(name) + " " + className + " " + formatBirthday(birthday) + " " + String.format("%.2f", GPA);
}
}
public class J05005 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = Integer.parseInt(sc.nextLine());
ArrayList<Student3> list = new ArrayList<>();
while (t-- > 0) {
String name = sc.nextLine();
String className = sc.nextLine();
String birthday = sc.nextLine();
float GPA = sc.nextFloat();
sc.nextLine();
list.add(new Student3(name, className, birthday, GPA));
}
Collections.sort(list);
for (Student3 i : list) {
System.out.println(i);
}
}
}