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.466
Trong 16.490 thành viên
Điểm
2
Tính theo trọng số, xem tab Bài tập

Bài đã giải

1 bài đạt trọn điểm trong 1 nhóm

Phân tích thành phần điểm

Điểm hồ sơ (2) là tổng có trọng số: các bài được xếp theo điểm từ cao xuống thấp, bài đầu tiên tính 100%, mỗi bài sau tính 95% trọng số của bài trước; sau đó cộng điểm thưởng theo số bài đã giải.

Các bài đóng góp nhiều điểm nhất vào điểm hồ sơ của minhhieu: nhóm, bài nộp tốt nhất, điểm test, điểm bài, trọng số và phần đóng góp
Bài tập Nhóm Lúc nộp Ngôn ngữ Kết quả Điểm test Điểm bài Trọng số Đóng góp
Quản lý điểm Nhập môn lập trình C++20 ACChấp nhận 10 / 10 1 100% 1
Hiển thị 1 trong 1 bài có điểm