Skip to content

Commit 3180cf8

Browse files
IR
1 parent a475786 commit 3180cf8

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package Handling_File.DS_SinhVienFileVB;
7+
8+
/**
9+
*
10+
* @author Admin
11+
*/
12+
import java.io.*;
13+
import java.util.*;
14+
public class DanhSach {
15+
public static void main(String[] args) throws FileNotFoundException {
16+
File myFile = new File("SINHVIEN.in");
17+
Scanner input = new Scanner(myFile);
18+
int test = Integer.parseInt(input.nextLine());
19+
ArrayList<SinhVien> arr = new ArrayList<>();
20+
for(int i=1;i<=test;i++){
21+
String ten = input.nextLine();
22+
String lop = input.nextLine();
23+
String ngSinh = input.nextLine();
24+
float gpa = Float.parseFloat(input.nextLine());
25+
SinhVien sv = new SinhVien(i,ten,lop,ngSinh,gpa);
26+
arr.add(sv);
27+
}
28+
for(SinhVien i: arr){
29+
System.out.println(i.toString());
30+
}
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
1
2+
nGuyEn vaN biNH
3+
D20CQCN01-B
4+
2/12/2002
5+
3.1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package Handling_File.DS_SinhVienFileVB;
7+
8+
/**
9+
*
10+
* @author Admin
11+
*/
12+
import java.text.ParseException;
13+
import java.text.SimpleDateFormat;
14+
import java.util.Date;
15+
import java.util.logging.Level;
16+
import java.util.logging.Logger;
17+
public class SinhVien {
18+
private int id;
19+
private String ten, lop, ngSinh;
20+
private float gpa;
21+
22+
public SinhVien(int id, String ten, String lop, String ngSinh, float gpa) {
23+
this.id = id;
24+
this.ten = ten;
25+
this.lop = lop;
26+
this.ngSinh = ngSinh;
27+
this.gpa = gpa;
28+
}
29+
30+
public String getTen() {
31+
String[] tmp = ten.toLowerCase().split("\\s+");
32+
String res = "";
33+
for(int i=0;i<tmp.length;i++){
34+
String s1 = tmp[i].substring(0,1).toUpperCase() + tmp[i].substring(1);
35+
res += s1 + " ";
36+
}
37+
return res;
38+
}
39+
40+
41+
public String getId() {
42+
String res = "";
43+
if(id >= 10){
44+
res += "B20DCCN0" + String.valueOf(id);
45+
}
46+
else{
47+
res += "B20DCCN00" + String.valueOf(id);
48+
}
49+
return res;
50+
}
51+
52+
public String getNgSinh(){
53+
SimpleDateFormat formater = new SimpleDateFormat("dd/MM/yyyy");
54+
Date date = null;
55+
try {
56+
date = formater.parse(ngSinh);
57+
} catch (ParseException ex) {
58+
Logger.getLogger(SinhVien.class.getName()).log(Level.SEVERE, null, ex);
59+
}
60+
String dob = formater.format(date);
61+
return dob;
62+
}
63+
64+
public String getGpa() {
65+
String res = String.valueOf(gpa);
66+
if(res.length()== 3){
67+
res += "0";
68+
}
69+
return res;
70+
}
71+
72+
@Override
73+
public String toString() {
74+
return getId() + " " + getTen() + lop + " " + getNgSinh() + " " + getGpa();
75+
}
76+
77+
78+
}

0 commit comments

Comments
 (0)