-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ05003.java
More file actions
49 lines (42 loc) · 1.34 KB
/
Copy pathJ05003.java
File metadata and controls
49 lines (42 loc) · 1.34 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
//src/J05003.java
import java.util.*;
public class J05003 {
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);
}
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 String toString() {
StringBuilder sb = new StringBuilder(this.ngaySinh);
if (sb.charAt(2) != '/') {
sb.insert(0, "0");
}
if (sb.charAt(5) != '/') {
sb.insert(3, "0");
}
return this.msv + " " + this.name + " " + this.lop + " " + sb.toString() + " " + String.format("%.2f", this.gpa);
}
}