By Nguyễn Tiền Khôi| 15:27 19/06/2023|
Java Basic

Quản Lí Cán Bộ

Đề bài: 

Một đơn vị sản xuất gồm có các cán bộ là công nhân, kỹ sư,nhân viên.

• Mỗi cán bộ cần quản lý lý các thuộc tính: Họ tên, ngày sinh, giới tính,địa chỉ

• Các công nhân cần quản lý: Bậc (công nhân bậc 3/7, bậc 4/7 …)

• Các kỹ sư cần quản lý: Ngành đào tạo

• Các nhân viên phục vụ cần quản lý thông tin: công việc1.

Xây dựng các lớp NhanVien, CongNhan, KySu kế thừa từ lớp CanBo

2.Xây dựng các hàm để truy nhập (get), thay đổi (set) và hiển thị thôngtin về các thuộc tính của các lớp (nếu cần).

3. Xây dựng lớp QLCB cài đặt các phương thức thực hiện các chức năngsau:

• Nhập thông tin mới cho cán bộ

• Tìm kiếm theo họ tên

• Hiển thị thông tin cán bộ tìm được  

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

5

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

GokiSoft.com [Teacher]
GokiSoft.com

2021-07-30 02:11:22


#QLCB.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 lesson11.bt2270;

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

/**
 *
 * @author Diep.Tran
 */
public class QLCB {
    static List<CanBo> canBoList = new ArrayList<>();
    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:
                    inputData();
                    break;
                case 2:
                    searchByName();
                    break;
                case 3:
                    showData();
                    break;
                case 4:
                    System.out.println("Thoat!!!");
                    break;
                default:
                    System.out.println("Nhap sai!!!");
                    break;
            }
        } while(choose != 4);
    }
    
    static void showMenu() {
        System.out.println("1. Nhap thong tin moi cho can bo");
        System.out.println("2. Tim kiem theo ten");
        System.out.println("3. Hien thi thong tin");
        System.out.println("4. Thoat");
        System.out.println("Chon: ");
    }

    static void inputData() {
        System.out.println("Nhap so can bo can them: ");
        int n = Integer.parseInt(scan.nextLine());
        
        for (int i = 0; i < n; i++) {
            CanBo canBo = createCanbo();
            
            canBoList.add(canBo);
        }
    }
    
    static CanBo createCanbo() {
        CanBo canBo;
        
        System.out.println("1. Nhap thong tin Cong Nhan");
        System.out.println("2. Nhap thong tin Ky Su");
        System.out.println("3. Nhap thong tin Nhan Vien Phuc Vu");
        System.out.println("Chon: ");
        
        int choose = Integer.parseInt(scan.nextLine());
        
        switch(choose) {
            case 1:
                canBo = new CongNhan();
                break;
            case 2:
                canBo = new KySu();
                break;
            default:
                canBo = new NVPhucVu();
                break;
        }
        canBo.input();
        
        return canBo;
    }

    static void searchByName() {
        System.out.println("Nhap ten can bo can tim kiem: ");
        String fullname = scan.nextLine();
        
        for (CanBo canBo : canBoList) {
            if(canBo.getFullname().equalsIgnoreCase(fullname)) {
                canBo.display();
            }
        }
    }

    static void showData() {
        canBoList.forEach(canBo -> {
            canBo.display();
        });
    }
}


#NVPhucVu.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 lesson11.bt2270;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class NVPhucVu extends CanBo{
    String congViec;

    public NVPhucVu() {
    }

    public NVPhucVu(String congViec, String fullname, String birthday, String gender, String address) {
        super(fullname, birthday, gender, address);
        this.congViec = congViec;
    }

    public String getCongViec() {
        return congViec;
    }

    public void setCongViec(String congViec) {
        this.congViec = congViec;
    }

    @Override
    public String toString() {
        return super.toString() + ", cong viec= " + congViec;
    }

    @Override
    public void input() {
        super.input();
        
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap cong viec: ");
        congViec = scan.nextLine();
    }
    
}


#KySu.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 lesson11.bt2270;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class KySu extends CanBo{
    String nganh;

    public KySu() {
    }

    public KySu(String nganh, String fullname, String birthday, String gender, String address) {
        super(fullname, birthday, gender, address);
        this.nganh = nganh;
    }

    public String getNganh() {
        return nganh;
    }

    public void setNganh(String nganh) {
        this.nganh = nganh;
    }

    @Override
    public String toString() {
        return super.toString() + ", nganh= " + nganh;
    }

    @Override
    public void input() {
        super.input(); //To change body of generated methods, choose Tools | Templates.
        
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap nganh: ");
        nganh = scan.nextLine();
    }
    
}


#CongNhan.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 lesson11.bt2270;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class CongNhan extends CanBo{
    public static final int BAC_MAX = 7;
    
    int bac;//bac: 1 -> 7

    public CongNhan() {
    }

    public CongNhan(int bac, String fullname, String birthday, String gender, String address) {
        super(fullname, birthday, gender, address);
        this.bac = bac;
    }

    public int getBac() {
        return bac;
    }

    public void setBac(int bac) {
        this.bac = bac;
    }

    @Override
    public String toString() {
        return super.toString() + ", bac= " + bac;
    }

    @Override
    public void input() {
        super.input(); //To change body of generated methods, choose Tools | Templates.
        
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap bac cong nhan: ");
        bac = Integer.parseInt(scan.nextLine());
    }
}


#CanBo.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 lesson11.bt2270;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class CanBo {
    String fullname, birthday, gender, address;

    public CanBo() {
    }

    public CanBo(String fullname, String birthday, String gender, String address) {
        this.fullname = fullname;
        this.birthday = birthday;
        this.gender = gender;
        this.address = address;
    }

    public String getFullname() {
        return fullname;
    }

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

    public String getBirthday() {
        return birthday;
    }

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

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getAddress() {
        return address;
    }

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

    @Override
    public String toString() {
        return "fullname=" + fullname + ", birthday=" + birthday + ", gender=" + gender + ", address=" + address;
    }
    
    public void display() {
        System.out.println(this);
    }
    
    public void input() {
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap ten: ");
        fullname = scan.nextLine();
        
        System.out.println("Nhap ngay sinh: ");
        birthday = scan.nextLine();
        
        System.out.println("Nhap gioi tinh: ");
        gender = scan.nextLine();
        
        System.out.println("Nhap dia chi: ");
        address = scan.nextLine();
    }
}