Bỏ qua đến nội dung

minhhieu

Chưa có rating
Thành viên của

package HoangDuongMinhHieu;

import java.io.BufferedReader; import java.io.FileReader; import java.sql.Connection; import java.sql.Driver; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.util.ArrayList;

import On.Sach;

public class Main { private final static String Ten_file = "D:\javacoban\HoTenSV.txt"; public static void main(String[] args) { ArrayList<ThietBiCN> ds = new ArrayList<>();

    System.out.println("---------cau1--------");
    try {
        BufferedReader br = new BufferedReader(
                new FileReader(Ten_file));
        String line;
        while ((line=br.readLine())!= null) {
            System.out.println(line);
        }
        br.close();
    } catch (Exception e) {
        System.out.println("Loi: " + e.getMessage());
    }
    System.out.println("----------cau2----------");

    try {
        BufferedReader br = new BufferedReader(
                new FileReader(Ten_file));
        String line;
        while((line = br.readLine())!= null) {
            String[] a = line.split("\\|");
            if(a.length<5) {
                continue;
            }
            String loai=a[0].trim();
            String ma = a[1].trim();
            String ten = a[2].trim();
            int nam = Integer.parseInt(a[3].trim());
            String giaTri = a[4].trim();

            if(loai.equals("MT")) {
                MayTinh mt = new MayTinh(ma, ten, nam, giaTri);
                ds.add(mt);
            }
            else if(loai.equals("MC")) {
                MayChieu mc =new MayChieu(ma, ten, nam, giaTri);
                ds.add(mc);
            }
        }
        br.close();
    } catch (Exception e) {
        System.out.println("Loi: " + e.getMessage());
    }
    System.out.println("----------Danh sách Máy tính----------");
    for (ThietBiCN x : ds) {
        if ( x instanceof MayTinh) {
            x.hienthi();
        }
    }
    System.out.println("----------Danh sách Máy chiếu----------");
    for(ThietBiCN x : ds) {
        if(x instanceof MayChieu) {
            x.hienthi();
        }
    }
    System.out.println("----------Câu 3----------");
    String url= "jdbc:sqlserver://localhost:1433;databaseName=Thietbi;encrypt=false;";
    String user ="sa";
    String pass= "123";

    try {
        Connection conn= DriverManager.getConnection(url,user,pass);
        String qlMT = "insert into Maytinh ([Mã thiết bị],[Tên thiết bị],Năm,Ram) values (?,?,?,?)";
        String qlMC = "insert into MayChieu([Mã thiết bị],[Tên thiết bị],Năm,[Độ phân giải]) values (?,?,?,?)";

        PreparedStatement psMT= conn.prepareStatement(qlMT);
        PreparedStatement psMC= conn.prepareStatement(qlMC);

        for(ThietBiCN x : ds) {
            if(x instanceof MayTinh) {
                MayTinh mt = (MayTinh)x;
                psMT.setString(1, mt.getMaTB());
                psMT.setString(2, mt.getMaTB());
                psMT.setInt(3, mt.getNamTB());
                psMT.setString(4, mt.getRAM());

                psMT.executeUpdate();
            }
        }
        for(ThietBiCN x : ds) {
            if(x instanceof MayChieu) {
                MayChieu mc = (MayChieu)x;
                psMC.setString(1, mc.getMaTB());
                psMC.setString(2, mc.getTenTB());
                psMC.setInt(3, mc.getNamTB());
                psMC.setString(4, mc.getDoPG());

                psMC.executeUpdate();
            }
        }
        System.out.println("Đã lưu vào sql");
        psMC.close();
        psMT.close();
        conn.close();
    } catch (Exception e) {
        System.out.println("Lỗi " + e.getMessage());
    }
    System.out.println("\n----------Câu 4----------");

    int dem = 0;

    for (ThietBiCN x : ds) {

        if (x instanceof MayTinh) {

            MayTinh mt = (MayTinh) x;

            if (mt.getRAM().equals("16GB")) {
                dem++;
            }
        }
    }

    System.out.println("-------------------------");
    System.out.println("RAM        Số lượng");
    System.out.println("-------------------------");
    System.out.println("16GB       " + dem);
    System.out.println("-------------------------");
}

}

Luyện tập

Bài đã giải
1
Chỉ tính bài đạt trọn điểm
Hạng theo điểm
#7.465
Trong 16.490 thành viên
Điểm
2
Tính theo trọng số, xem tab Bài tập

Lịch sử rating

Rating chỉ thay đổi sau các kỳ thi có tính rating

Chưa tham gia kỳ thi có tính rating

Rating của minhhieu sẽ hiện ở đây sau kỳ thi có tính rating đầu tiên.

Hoạt động

38 bài nộp trong 12 tháng qua

Ít Nhiều Năm mức màu theo số bài nộp trong ngày: 0 bài nộp; 1–3 bài nộp; 4–7 bài nộp; 8–10 bài nộp; 11–14 bài nộp.
Số ngày có bài nộp
5 ngày
Ngày nhiều nhất
14 bài nộp, ngày 24/08/2026
Tháng nhiều nhất
32 bài nộp, tháng 08/2026
Số bài nộp theo tháng, từ 26/10/2025 đến 25/10/2026
ThángBài nộpSố ngày có bài nộp
Tháng 10/202500
Tháng 11/202500
Tháng 12/202500
Tháng 01/202600
Tháng 02/202600
Tháng 03/202600
Tháng 04/202600
Tháng 05/202600
Tháng 06/202600
Tháng 07/202661
Tháng 08/2026324
Tháng 09/202600
Tháng 10/202600