package testingtx2_2;

import java.io.Serializable;
import java.util.Scanner;

public abstract class HocVien implements Serializable{
    protected String HoTen;
    protected String DiaChi;
    protected int LoaiUT;
    protected String LoaiCT;

    public HocVien() {
    }

    public HocVien(String HoTen, String DiaChi, int LoaiUT, String LoaiCT) {
        this.HoTen = HoTen;
        this.DiaChi = DiaChi;
        this.LoaiUT = LoaiUT;
        this.LoaiCT = LoaiCT;
    }

    public String getHoTen() {
        return HoTen;
    }

    public String getDiaChi() {
        return DiaChi;
    }

    public int getLoaiUT() {
        return LoaiUT;
    }

    public String getLoaiCT() {
        return LoaiCT;
    }

    public void setHoTen(String HoTen) {
        this.HoTen = HoTen;
    }

    public void setDiaChi(String DiaChi) {
        this.DiaChi = DiaChi;
    }

    public void setLoaiUT(int LoaiUT) {
        this.LoaiUT = LoaiUT;
    }

    public void setLoaiCT(String LoaiCT) {
        this.LoaiCT = LoaiCT;
    }
    
    public void NhapThongTin(){
        Scanner sc = new Scanner(System.in);
        System.out.print("\nNhap vao ho ten : ");
        HoTen = sc.nextLine();
        System.out.print("\nNhap vao dia chi : ");
        DiaChi = sc.nextLine();
        System.out.print("\nNhap vao loai uu tien : ");
        LoaiUT = sc.nextInt();
        sc.nextLine();
        System.out.print("\nNhap vao loai chuong trinh : ");
        LoaiCT = sc.nextLine();
    }
    
    public void InThongTin(){
        System.out.print(String.format("\n%20s %20s %20d %20s %20.2f", HoTen, DiaChi, LoaiUT, LoaiCT, hocPhi()));
    }
    
    public abstract double hocPhi();
}
----------------
package testingtx2_2;

import java.io.Serializable;
import java.util.Objects;
import java.util.Scanner;

public class HocVienLT extends HocVien implements Serializable{
    int SoBuoi;
    double DonGiaLT;

    public HocVienLT() {
    }

    public HocVienLT(int SoBuoi, double DonGiaLT, String HoTen, String DiaChi, int LoaiUT, String LoaiCT) {
        super(HoTen, DiaChi, LoaiUT, LoaiCT);
        this.SoBuoi = SoBuoi;
        this.DonGiaLT = DonGiaLT;
    }

    public int getSoBuoi() {
        return SoBuoi;
    }

    public double getDonGiaLT() {
        return DonGiaLT;
    }

    public void setSoBuoi(int SoBuoi) {
        this.SoBuoi = SoBuoi;
    }

    public void setDonGiaLT(double DonGiaLT) throws Exception{
        this.DonGiaLT = DonGiaLT;
    }

    @Override
    public void NhapThongTin() {
        try{
            super.NhapThongTin();
            Scanner sc = new Scanner(System.in);
            System.out.print("\nNhap vao so buoi : ");
            SoBuoi= sc.nextInt();
            System.out.print("\nNhap vao don gia lt : ");
            do{
                DonGiaLT = sc.nextDouble();
                if(DonGiaLT <= 10000)
                    throw new Exception("Don gia can > 10000");
            }while(DonGiaLT <= 0);
        }
        catch(Exception ex){
            System.out.println(ex);
        }
    }

    @Override
    public double hocPhi() {
        double HocPhi = SoBuoi * DonGiaLT;
        if(LoaiUT == 1)
            return HocPhi - 1000000;
        return HocPhi - 800000;
    }

    @Override
    public boolean equals(Object obj) {
        HocVienLT hvlt = (HocVienLT)obj;
        return this.HoTen.equals(hvlt.HoTen) 
                && this.DiaChi.equals(hvlt.DiaChi) 
                && this.LoaiUT == hvlt.LoaiUT 
                && this.LoaiCT.equals(hvlt.LoaiCT)
                && this.SoBuoi == hvlt.SoBuoi
                && this.DonGiaLT == hvlt.DonGiaLT;
    }

    @Override
    public int hashCode() {
        return HoTen.hashCode() + DiaChi.hashCode() + LoaiUT + LoaiCT.hashCode() + SoBuoi + Double.hashCode(DonGiaLT);
    }
}
---------------
package testingtx2_2;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashSet;
import java.util.Scanner;

public class Demo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashSet<HocVienLT> hs = new HashSet<HocVienLT>();
        FakeData(hs);
        InHashSet(hs);
        
        int n;
        System.out.print("\nNhap vao so luong hoc vien muon them : ");
        n = sc.nextInt();
        
        for(int i=0; i<n; i++){
            System.out.print("\n======= Nhap vao hoc vien lt ==========");
            HocVienLT them = new HocVienLT();
            them.NhapThongTin();
            hs.add(them);
        }
        
        System.out.println("\n============ DS SAU KHI THEM ==============");
        InHashSet(hs);
        
        System.out.println("\n============ Ghi FILE ==============");
        try{
            GhiFile(hs);
            System.out.print("\nGhi file thanh cong");
        }catch(Exception ex){
            System.out.println(ex);
        }
        
        System.out.println("\n============ Doc FILE ==============");
        try{
            HashSet<HocVienLT> hsThem;
            hsThem = DocFile();
            InHashSet(hsThem);
        }catch(Exception ex){
            System.out.println(ex);
        }
    }
    
    public static void FakeData(HashSet<HocVienLT> hs){
        hs.add(new HocVienLT(21, 5000000, "Nguyen An", "Ha Noi", 1, "Lap trinh"));
        hs.add(new HocVienLT(22, 4500000, "Nguyen Nam", "Ha Noi", 2, "Lap trinh"));
        hs.add(new HocVienLT(26, 300000, "Nguyen Hoang", "Ha Noi", 1, "Lap trinh"));
    }
    
    public static void InHashSet(HashSet<HocVienLT> hs){
        System.out.print(String.format("\n%20s %20s %20s %20s %20s", "Ho Ten", "Dia Chi", "Loai UT", "Loai CT", "Hoc phi"));
        for(HocVienLT i : hs)
            i.InThongTin();
    }
    
    public static void GhiFile(HashSet<HocVienLT> hs) throws Exception{
        FileOutputStream fo = new FileOutputStream("HocVienLT.TXT");
        ObjectOutputStream out = new ObjectOutputStream(fo);
        out.writeObject(hs);
        out.close();
    }
    
    public static HashSet<HocVienLT> DocFile() throws Exception{
        HashSet<HocVienLT> hs;
        FileInputStream fi = new FileInputStream("HocVienLT.TXT");
        ObjectInputStream in = new ObjectInputStream(fi);
        hs = (HashSet<HocVienLT>)in.readObject();
        in.close();
        return hs;
    }
}
giải thích đoạn code trên bằng tiếng việt