-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJ04006.java
68 lines (54 loc) · 1.51 KB
/
J04006.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
//src/J04006.java
import java.util.Scanner;
public class J04006 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
SinhVien x = new SinhVien();
x.setMaSV("B20DCCN001");
x.setHoTen(sc.nextLine());
x.setLop(sc.nextLine());
x.setNgaySinh(sc.nextLine());
x.setGpa(sc.nextDouble());
System.out.println(x);
}
}
//src/SinhVien.java
class SinhVien {
private String maSV;
private String hoTen;
private String lop;
private String ngaySinh;
private double gpa;
public SinhVien() {
this.maSV = "";
this.hoTen = "";
this.lop = "";
this.ngaySinh = "";
this.gpa = 0;
}
public void setMaSV(String maSV) {
this.maSV = maSV;
}
public void setHoTen(String hoTen) {
this.hoTen = hoTen;
}
public void setLop(String lop) {
this.lop = lop;
}
public void setNgaySinh(String ngaySinh) {
this.ngaySinh = ngaySinh;
}
public void setGpa(double gpa) {
this.gpa = gpa;
}
public String toString() {
StringBuilder sb = new StringBuilder(this.ngaySinh);
if (sb.charAt(1) == '/') {
sb.insert(0, '0');
}
if (sb.charAt(4) == '/') {
sb.insert(3, '0');
}
return this.maSV + " " + this.hoTen + " " + this.lop + " " + sb.toString() + " " + String.format("%.2f", this.gpa);
}
}