|
| 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