By GokiSoft.com| 10:27 21/09/2021|
Java Advanced

Bài tập - Chương trình quản lý Test nhanh PCR - COVID19 - Lập trình Java nâng cao.

Bạn được yêu cầu phát triển một chức năng cho TYT về việc quản lý Test nhanh PCR - Trong phòng chống dịch COVID-19 trên địa bàn.

Yêu cầu thông tin cần quản lý: 

Bảng PatternInfo gồm các column: id tự tăng, mã mẫu TEST, tên, năm sinh, địa chỉ hiện tại, địa chỉ lấy mẫu, ngày lấy mẫu, kết quả (0 -> BT, 1 -> Dương tính COVID-19), ngày có kết quả.

Yêu cầu phát triển các chức năng sau: (Java Console)

1. Nhập thông tin lấy mẫu -> Mỗi lần nhập 1 mẫu vào database -> Sau mỗi mẫu hỏi người dùng có tiếp tục ko -> Nếu người dùng nhập 'N' hoặc 'n' thì dừng nhập

2. Hiển thị tất cả các mẫu theo 1 ngày nhập vào từ bàn phím

3. Hiển thị tất cả các mẫu theo địa chỉ lấy mẫu nhập vào từ bàn phím

4. Nhập kết quả Test -> Nhập mã mẫu TEST + Kết quả -> Tự động update dữ liệu theo mã mẫu TEST và kết quả vào database -> Chú ý: Mã mẫu TEST có thể trùng nhau với nhiều người (Do chương trình test nhanh áp dụng - Test theo lô)

5. Báo cáo kết quả âm tinh, dương tính với COVID-19 theo 1 ngày

6. Xuất báo cáo kết quả ra file txt theo định dạng sau:

Mã mẫu TEST, Tên, Năm Sinh, Địa chỉ lấy mẫu, ngày lấy, ngày có kết quả, kết quả

7. Thoát.

Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

Đào Mạnh Dũng [C2010L]
Đào Mạnh Dũng

2021-09-07 14:20:17


#Config.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pkg2390;

/**
 *
 * @author Diep.Tran
 */
public interface Config {
    String DB_URL = "jdbc:mysql://localhost:3306/covid19";
    String USERNAME = "root";
    String PASSWORD = "";
}


#Main.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pkg2390;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Diep.Tran
 */
public class Main {

    static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
        int choose;

        do {
            showMenu();
            choose = Integer.parseInt(scan.nextLine());

            switch (choose) {
                case 1:
                    input();
                    break;
                case 2:
                    searchByDate();
                    break;
                case 3:
                    searchByAddress();
                    break;
                case 4:
                    updatePattern();
                    break;
                case 5:
                    break;
                case 6:
                    FileOutputStream fo = null;
                    
                {
                    try {
                        fo = new FileOutputStream("file.txt",false);
                        fo.write("Mã mẫu TEST, Tên, Năm Sinh, Địa chỉ lấy mẫu, ngày lấy, ngày có kết quả, kết quả\n".getBytes());
                        List<PatternInfo> dataList = PatternInfoModify.search();
                        for (PatternInfo patternInfo : dataList) {
                            fo.write(patternInfo.file());
                        }        
                    } catch (FileNotFoundException ex) {
                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (IOException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                } finally{
                        if (fo!=null) {
                            try {
                                fo.close();
                            } catch (IOException ex) {
                                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                    }
                }
                    break;

                case 7:
                    System.out.println("Thoat!!!");
                    System.exit(0);
                    break;
                default:
                    System.out.println("Nhap sai!!!");
                    break;
            }
        } while (choose != 7);
    }

    static void showMenu() {
        System.out.println("1. Nhap");
        System.out.println("2. Hien thi theo ngay");
        System.out.println("3. Hien thi theo dia chi");
        System.out.println("4. Cap nhat ket qua");
        System.out.println("5. Bao cao");
        System.out.println("6. Xuat du lieu");
        System.out.println("7. Thoat");
        System.out.println("Chon: ");
    }

    private static void input() {
        String option;
        do {
            PatternInfo info = new PatternInfo();
            info.input();
            
            PatternInfoModify.insert(info);
            System.out.println("Ban co tiep tuc nhap hay ko Y/n?");
            option = scan.nextLine();
        } while(!option.equalsIgnoreCase("N"));
    }

    private static void searchByDate() {
        System.out.println("Nhap ngay can tim kiem (yyyy-MM-dd): ");
        String searchDate = scan.nextLine();
        
        List<PatternInfo> dataList = PatternInfoModify.searchByDate(searchDate);
        for (PatternInfo patternInfo : dataList) {
            System.out.println(patternInfo);
        }
    }
    
    private static void searchByDateCovid19() {
        System.out.println("Nhap ngay can tim kiem (yyyy-MM-dd): ");
        String searchDate = scan.nextLine();
        
        List<PatternInfo> dataList = PatternInfoModify.searchByDate(searchDate);
        for (PatternInfo patternInfo : dataList) {
            if (patternInfo.result==1) {
                System.out.println("Dương tính"+ patternInfo);
            }
            
        }
        System.out.println();
        System.out.println();
        for (PatternInfo patternInfo : dataList) {
            if (patternInfo.result==0) {
                System.out.println("Âm tính"+ patternInfo);
            }
            
        }
    }

    private static void searchByAddress() {
        System.out.println("Nhap dia chi TEST can xem: ");
        String address = scan.nextLine();
        
        List<PatternInfo> dataList = PatternInfoModify.searchByAddress(address);
        for (PatternInfo patternInfo : dataList) {
            System.out.println(patternInfo);
        }
    }

    private static void updatePattern() {
        System.out.println("Nhap mau TEST: ");
        String patternNo = scan.nextLine();
        
        System.out.println("Nhap ket qua: ");
        int result = Integer.parseInt(scan.nextLine());
        
        PatternInfoModify.update(patternNo, result);
    }
}


#PatternInfo.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pkg2390;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class PatternInfo {
    int id, birthday, result;
    String fullname, patternNo, career, address, addressTest, createdAt, updatedAt;

    public PatternInfo() {
    }

    public PatternInfo(int id, int birthday, int result, String fullname, String patternNo, String career, String address, String addressTest, String createdAt, String updatedAt) {
        this.id = id;
        this.birthday = birthday;
        this.result = result;
        this.fullname = fullname;
        this.patternNo = patternNo;
        this.career = career;
        this.address = address;
        this.addressTest = addressTest;
        this.createdAt = createdAt;
        this.updatedAt = updatedAt;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getBirthday() {
        return birthday;
    }

    public void setBirthday(int birthday) {
        this.birthday = birthday;
    }

    public int getResult() {
        return result;
    }

    public void setResult(int result) {
        this.result = result;
    }

    public String getFullname() {
        return fullname;
    }

    public void setFullname(String fullname) {
        this.fullname = fullname;
    }

    public String getPatternNo() {
        return patternNo;
    }

    public void setPatternNo(String patternNo) {
        this.patternNo = patternNo;
    }

    public String getCareer() {
        return career;
    }

    public void setCareer(String career) {
        this.career = career;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getAddressTest() {
        return addressTest;
    }

    public void setAddressTest(String addressTest) {
        this.addressTest = addressTest;
    }

    public String getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(String createdAt) {
        this.createdAt = createdAt;
    }

    public String getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(String updatedAt) {
        this.updatedAt = updatedAt;
    }

    @Override
    public String toString() {
        return "PatternInfo{" + "id=" + id + ", birthday=" + birthday + ", result=" + result + ", fullname=" + fullname + ", patternNo=" + patternNo + ", career=" + career + ", address=" + address + ", addressTest=" + addressTest + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + '}';
    }
    
    public byte[] file() {
        return (id + "," + birthday + "," + result + "," + fullname + "," + patternNo + "," + career + "," + address + "," + addressTest + "," + createdAt + "," + updatedAt + "\n").getBytes();
    }
    
    public void input() {
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap ten: ");
        fullname = scan.nextLine();
        
        System.out.println("Nhap mau TEST: ");
        patternNo = scan.nextLine();
        
        System.out.println("Nhap nam sinh: ");
        birthday = Integer.parseInt(scan.nextLine());
        
        System.out.println("Nhap nghe nghiep: ");
        career = scan.nextLine();
        
        System.out.println("Nhap dia chi: ");
        address = scan.nextLine();
        
        System.out.println("Nhap dia chi lay mau: ");
        addressTest = scan.nextLine();
    }
}


#PatternInfoModify.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pkg2390;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Diep.Tran
 */
public class PatternInfoModify {
    static Connection conn = null;
    static PreparedStatement statement = null;
    
    static void openConnection() {
        try {
            conn = DriverManager.getConnection(Config.DB_URL, Config.USERNAME, Config.PASSWORD);
        } catch (SQLException ex) {
            Logger.getLogger(PatternInfoModify.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    static void closeConnection() {
        if(statement != null) {
            try {
                statement.close();
            } catch (SQLException ex) {
                Logger.getLogger(PatternInfoModify.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        if(conn != null) {
            try {
                conn.close();
            } catch (SQLException ex) {
                Logger.getLogger(PatternInfoModify.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    
    public static void insert(PatternInfo info) {
        openConnection();
        
        try {
            String sql = "insert into pattern_info (pattern_no, fullname, birthday, career, address, address_test, created_at, updated_at, result) "
                + "values (?, ?, ?, ?, ?, ?, ?, ?, ?)";
            statement = conn.prepareStatement(sql);
            
            Date date = Calendar.getInstance().getTime();  
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");  
            String strDate = dateFormat.format(date);  
            
            statement.setString(1, info.getPatternNo());
            statement.setString(2, info.getFullname());
            statement.setInt(3, info.getBirthday());
            statement.setString(4, info.getCareer());
            statement.setString(5, info.getAddress());
            statement.setString(6, info.getAddressTest());
            statement.setString(7, strDate);
            statement.setString(8, strDate);
            statement.setInt(9, info.getResult());
            
            statement.execute();
        } catch (SQLException ex) {
            Logger.getLogger(PatternInfoModify.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        closeConnection();
    }
    
    public static void update(String patternNo, int result) {
        openConnection();
        
        try {
            String sql = "update pattern_info set result = ? where pattern_no = ?";
            statement = conn.prepareStatement(sql);
            
            statement.setInt(1, result);
            statement.setString(2, patternNo);
            
            statement.execute();
        } catch (SQLException ex) {
            Logger.getLogger(PatternInfoModify.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        closeConnection();
    }
    
    public static List<PatternInfo> searchByDate(String searchData) {
        List<PatternInfo> dataList = new ArrayList<>();
        
        openConnection();
        
        try {
            String sql = "select * from pattern_info where created_at >= ? and created_at < ?";
            statement = conn.prepareStatement(sql);
            
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar c = Calendar.getInstance();
            c.setTime(sdf.parse(searchData));
            c.add(Calendar.DATE, 1);  // number of days to add
            String nextDate = sdf.format(c.getTime());  // dt is now the new date
            
            statement.setString(1, searchData);
            statement.setString(2, nextDate);
            
            ResultSet resultSet = statement.executeQuery();
            
            while(resultSet.next()) {
                PatternInfo info = new PatternInfo(
                        resultSet.getInt("id"), 
                        resultSet.getInt("birthday"), 
                        resultSet.getInt("result"), 
                        resultSet.getString("fullname"), 
                        resultSet.getString("pattern_no"), 
                        resultSet.getString("career"), 
                        resultSet.getString("address"), 
                        resultSet.getString("address_test"), 
                        resultSet.getString("created_at"), 
                        resultSet.getString("updated_at")
                );
                dataList.add(info);
            }
        } catch (SQLException ex) {
            Logger.getLogger(PatternInfoModify.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParseException ex) {
            Logger.getLogger(PatternInfoModify.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        closeConnection();
        
        return dataList;
    }
    
    public static List<PatternInfo> searchByAddress(String address) {
        List<PatternInfo> dataList = new ArrayList<>();
        
        openConnection();
        
        try {
            String sql = "select * from pattern_info where address_test like ?";
            statement = conn.prepareStatement(sql);
            
            statement.setString(1, address);
            
            ResultSet resultSet = statement.executeQuery();
            
            while(resultSet.next()) {
                PatternInfo info = new PatternInfo(
                        resultSet.getInt("id"), 
                        resultSet.getInt("birthday"), 
                        resultSet.getInt("result"), 
                        resultSet.getString("fullname"), 
                        resultSet.getString("pattern_no"), 
                        resultSet.getString("career"), 
                        resultSet.getString("address"), 
                        resultSet.getString("address_test"), 
                        resultSet.getString("created_at"), 
                        resultSet.getString("updated_at")
                );
                dataList.add(info);
            }
        } catch (SQLException ex) {
            Logger.getLogger(PatternInfoModify.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        closeConnection();
        
        return dataList;
    }
    
        public static List<PatternInfo> search() {
        List<PatternInfo> dataList = new ArrayList<>();
        
        openConnection();
        
        try {
            String sql = "select * from pattern_info";
            statement = conn.prepareStatement(sql);
            
            
            ResultSet resultSet = statement.executeQuery();
            
            while(resultSet.next()) {
                PatternInfo info = new PatternInfo(
                        resultSet.getInt("id"), 
                        resultSet.getInt("birthday"), 
                        resultSet.getInt("result"), 
                        resultSet.getString("fullname"), 
                        resultSet.getString("pattern_no"), 
                        resultSet.getString("career"), 
                        resultSet.getString("address"), 
                        resultSet.getString("address_test"), 
                        resultSet.getString("created_at"), 
                        resultSet.getString("updated_at")
                );
                dataList.add(info);
            }
        } catch (SQLException ex) {
            Logger.getLogger(PatternInfoModify.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        closeConnection();
        
        return dataList;
    }
}




GokiSoft.com [Teacher]
GokiSoft.com

2021-09-07 13:41:35


#PatternInfoModify.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package java2.lesson11.bt2390;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Diep.Tran
 */
public class PatternInfoModify {
    static Connection conn = null;
    static PreparedStatement statement = null;
    
    static void openConnection() {
        try {
            conn = DriverManager.getConnection(Config.DB_URL, Config.USERNAME, Config.PASSWORD);
        } catch (SQLException ex) {
            Logger.getLogger(PatternInfoModify.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    static void closeConnection() {
        if(statement != null) {
            try {
                statement.close();
            } catch (SQLException ex) {
                Logger.getLogger(PatternInfoModify.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        if(conn != null) {
            try {
                conn.close();
            } catch (SQLException ex) {
                Logger.getLogger(PatternInfoModify.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    
    public static void insert(PatternInfo info) {
        openConnection();
        
        try {
            String sql = "insert into pattern_info (pattern_no, fullname, birthday, career, address, address_test, created_at, updated_at, result) "
                + "values (?, ?, ?, ?, ?, ?, ?, ?, ?)";
            statement = conn.prepareStatement(sql);
            
            Date date = Calendar.getInstance().getTime();  
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");  
            String strDate = dateFormat.format(date);  
            
            statement.setString(1, info.getPatternNo());
            statement.setString(2, info.getFullname());
            statement.setInt(3, info.getBirthday());
            statement.setString(4, info.getCareer());
            statement.setString(5, info.getAddress());
            statement.setString(6, info.getAddressTest());
            statement.setString(7, strDate);
            statement.setString(8, strDate);
            statement.setInt(9, info.getResult());
            
            statement.execute();
        } catch (SQLException ex) {
            Logger.getLogger(PatternInfoModify.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        closeConnection();
    }
    
    public static void update(String patternNo, int result) {
        openConnection();
        
        try {
            String sql = "update pattern_info set result = ? where pattern_no = ?";
            statement = conn.prepareStatement(sql);
            
            statement.setInt(1, result);
            statement.setString(2, patternNo);
            
            statement.execute();
        } catch (SQLException ex) {
            Logger.getLogger(PatternInfoModify.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        closeConnection();
    }
    
    public static List<PatternInfo> searchByDate(String searchData) {
        List<PatternInfo> dataList = new ArrayList<>();
        
        openConnection();
        
        try {
            String sql = "select * from pattern_info where created_at >= ? and created_at < ?";
            statement = conn.prepareStatement(sql);
            
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar c = Calendar.getInstance();
            c.setTime(sdf.parse(searchData));
            c.add(Calendar.DATE, 1);  // number of days to add
            String nextDate = sdf.format(c.getTime());  // dt is now the new date
            
            statement.setString(1, searchData);
            statement.setString(2, nextDate);
            
            ResultSet resultSet = statement.executeQuery();
            
            while(resultSet.next()) {
                PatternInfo info = new PatternInfo(
                        resultSet.getInt("id"), 
                        resultSet.getInt("birthday"), 
                        resultSet.getInt("result"), 
                        resultSet.getString("fullname"), 
                        resultSet.getString("pattern_no"), 
                        resultSet.getString("career"), 
                        resultSet.getString("address"), 
                        resultSet.getString("address_test"), 
                        resultSet.getString("created_at"), 
                        resultSet.getString("updated_at")
                );
                dataList.add(info);
            }
        } catch (SQLException ex) {
            Logger.getLogger(PatternInfoModify.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParseException ex) {
            Logger.getLogger(PatternInfoModify.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        closeConnection();
        
        return dataList;
    }
    
    public static List<PatternInfo> searchByAddress(String address) {
        List<PatternInfo> dataList = new ArrayList<>();
        
        openConnection();
        
        try {
            String sql = "select * from pattern_info where address_test like ?";
            statement = conn.prepareStatement(sql);
            
            statement.setString(1, address);
            
            ResultSet resultSet = statement.executeQuery();
            
            while(resultSet.next()) {
                PatternInfo info = new PatternInfo(
                        resultSet.getInt("id"), 
                        resultSet.getInt("birthday"), 
                        resultSet.getInt("result"), 
                        resultSet.getString("fullname"), 
                        resultSet.getString("pattern_no"), 
                        resultSet.getString("career"), 
                        resultSet.getString("address"), 
                        resultSet.getString("address_test"), 
                        resultSet.getString("created_at"), 
                        resultSet.getString("updated_at")
                );
                dataList.add(info);
            }
        } catch (SQLException ex) {
            Logger.getLogger(PatternInfoModify.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        closeConnection();
        
        return dataList;
    }
}


#PatternInfo.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package java2.lesson11.bt2390;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class PatternInfo {
    int id, birthday, result;
    String fullname, patternNo, career, address, addressTest, createdAt, updatedAt;

    public PatternInfo() {
    }

    public PatternInfo(int id, int birthday, int result, String fullname, String patternNo, String career, String address, String addressTest, String createdAt, String updatedAt) {
        this.id = id;
        this.birthday = birthday;
        this.result = result;
        this.fullname = fullname;
        this.patternNo = patternNo;
        this.career = career;
        this.address = address;
        this.addressTest = addressTest;
        this.createdAt = createdAt;
        this.updatedAt = updatedAt;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getBirthday() {
        return birthday;
    }

    public void setBirthday(int birthday) {
        this.birthday = birthday;
    }

    public int getResult() {
        return result;
    }

    public void setResult(int result) {
        this.result = result;
    }

    public String getFullname() {
        return fullname;
    }

    public void setFullname(String fullname) {
        this.fullname = fullname;
    }

    public String getPatternNo() {
        return patternNo;
    }

    public void setPatternNo(String patternNo) {
        this.patternNo = patternNo;
    }

    public String getCareer() {
        return career;
    }

    public void setCareer(String career) {
        this.career = career;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getAddressTest() {
        return addressTest;
    }

    public void setAddressTest(String addressTest) {
        this.addressTest = addressTest;
    }

    public String getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(String createdAt) {
        this.createdAt = createdAt;
    }

    public String getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(String updatedAt) {
        this.updatedAt = updatedAt;
    }

    @Override
    public String toString() {
        return "PatternInfo{" + "id=" + id + ", birthday=" + birthday + ", result=" + result + ", fullname=" + fullname + ", patternNo=" + patternNo + ", career=" + career + ", address=" + address + ", addressTest=" + addressTest + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + '}';
    }
    
    public void input() {
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap ten: ");
        fullname = scan.nextLine();
        
        System.out.println("Nhap mau TEST: ");
        patternNo = scan.nextLine();
        
        System.out.println("Nhap nam sinh: ");
        birthday = Integer.parseInt(scan.nextLine());
        
        System.out.println("Nhap nghe nghiep: ");
        career = scan.nextLine();
        
        System.out.println("Nhap dia chi: ");
        address = scan.nextLine();
        
        System.out.println("Nhap dia chi lay mau: ");
        addressTest = scan.nextLine();
    }
}


#Main.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package java2.lesson11.bt2390;

import java.util.List;
import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class Main {

    static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
        int choose;

        do {
            showMenu();
            choose = Integer.parseInt(scan.nextLine());

            switch (choose) {
                case 1:
                    input();
                    break;
                case 2:
                    searchByDate();
                    break;
                case 3:
                    searchByAddress();
                    break;
                case 4:
                    updatePattern();
                    break;
                case 5:
                    break;
                case 6:
                    break;
                case 7:
                    System.out.println("Thoat!!!");
                    break;
                default:
                    System.out.println("Nhap sai!!!");
                    break;
            }
        } while (choose != 7);
    }

    static void showMenu() {
        System.out.println("1. Nhap");
        System.out.println("2. Hien thi theo ngay");
        System.out.println("3. Hien thi theo dia chi");
        System.out.println("4. Cap nhat ket qua");
        System.out.println("5. Bao cao");
        System.out.println("6. Xuat du lieu");
        System.out.println("7. Thoat");
        System.out.println("Chon: ");
    }

    private static void input() {
        String option;
        do {
            PatternInfo info = new PatternInfo();
            info.input();
            
            PatternInfoModify.insert(info);
            System.out.println("Ban co tiep tuc nhap hay ko Y/n?");
            option = scan.nextLine();
        } while(!option.equalsIgnoreCase("N"));
    }

    private static void searchByDate() {
        System.out.println("Nhap ngay can tim kiem (yyyy-MM-dd): ");
        String searchDate = scan.nextLine();
        
        List<PatternInfo> dataList = PatternInfoModify.searchByDate(searchDate);
        for (PatternInfo patternInfo : dataList) {
            System.out.println(patternInfo);
        }
    }

    private static void searchByAddress() {
        System.out.println("Nhap dia chi TEST can xem: ");
        String address = scan.nextLine();
        
        List<PatternInfo> dataList = PatternInfoModify.searchByAddress(address);
        for (PatternInfo patternInfo : dataList) {
            System.out.println(patternInfo);
        }
    }

    private static void updatePattern() {
        System.out.println("Nhap mau TEST: ");
        String patternNo = scan.nextLine();
        
        System.out.println("Nhap ket qua: ");
        int result = Integer.parseInt(scan.nextLine());
        
        PatternInfoModify.update(patternNo, result);
    }
}


#Config.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package java2.lesson11.bt2390;

/**
 *
 * @author Diep.Tran
 */
public interface Config {
    String DB_URL = "jdbc:mysql://localhost:3306/C2010G";
    String USERNAME = "root";
    String PASSWORD = "";
}