By GokiSoft.com| 14:34 19/09/2022|
Java Basic

[Source Code] Quản Lí Cán Bộ - C2109I

Quản Lí Cán Bộ


#CanBo.java


/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.gokisoft.lesson05.bt2270;

import java.util.Scanner;

/**
 *
 * @author diepvan
 */
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;
    }
    
    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();
    }

    @Override
    public String toString() {
        return "fullname=" + fullname + ", birthday=" + birthday + ", gender=" + gender + ", address=" + address;
    }
    
    public void display() {
        System.out.println(toString());
//        System.out.println(this);
    }
    
    public void test() {
        System.out.println("Test...");
    }
}


#CongNhan.java


/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.gokisoft.lesson05.bt2270;

import java.util.Scanner;

/**
 *
 * @author diepvan
 */
public class CongNhan extends CanBo{
    String level;

    public CongNhan() {
    }

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

    public String getLevel() {
        return level;
    }

    public void setLevel(String level) {
        this.level = level;
    }
    
    @Override
    public void input() {
        super.input();
        
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap bac luong: ");
        level = scan.nextLine();
    }

    @Override
    public String toString() {
        return super.toString() + ", level=" + level;
    }
    
    public void testCongNhan() {
        System.out.println("Cong nhan ...");
    }
}


#KySu.java


/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.gokisoft.lesson05.bt2270;

import java.util.Scanner;

/**
 *
 * @author diepvan
 */
public class KySu extends CanBo{
    String career;

    public KySu() {
    }

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

    public String getCareer() {
        return career;
    }

    public void setCareer(String career) {
        this.career = career;
    }
    
    public void input() {
        super.input();
        
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap nghe nghiep: ");
        career = scan.nextLine();
    }

    @Override
    public String toString() {
        return super.toString() + ", career=" + career;
    }
    
    public void testKySu() {
        System.out.println("ky su ...");
    }
}


#Main.java


/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.gokisoft.lesson05.bt2270;

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

/**
 *
 * @author diepvan
 */
public class Main {
    public static void main(String[] args) {
        //Test: T/c da hinh
        CongNhan cn = new CongNhan();
        NhanVien nv = new NhanVien();
        
        cn.testCongNhan();
        nv.testNhanVien();
        
        cn.test();
        nv.test();
        
        CanBo cb = new CanBo();
        cb.test();
        
        CanBo c1 = new CongNhan();
        c1.test();
        if(c1 instanceof CongNhan) {
            ((CongNhan) c1).testCongNhan();
        }
        
        c1 = new NhanVien();
        c1.test();
        
        if(c1 instanceof NhanVien) {
            ((NhanVien) c1).testNhanVien();
        }
        
        ArrayList<CanBo> dataList = new ArrayList<>();
        int choose;
        Scanner scan = new Scanner(System.in);
        
        do {
            showMenu();
            choose = Integer.parseInt(scan.nextLine());
            
            switch (choose) {
                case 1: {
                    System.out.println("Nhap so can bo can them: ");
                    int N = Integer.parseInt(scan.nextLine());
                    
                    for (int i = 0; i < N; i++) {
                        CanBo canbo;
                        
                        System.out.println("1. Khoi tao cong nhan");
                        System.out.println("2. Khoi tao ky su");
                        System.out.println("3. Khoi tao nhan vien");
                        System.out.println("Chon: ");
                        
                        int option = Integer.parseInt(scan.nextLine());
                        
                        switch (option) {
                            case 1:
                                canbo = new CongNhan();
                                break;
                            case 2:
                                canbo = new KySu();
                                break;
                            default:
                                canbo = new NhanVien();
                                break;
                        }
                        canbo.input();
                        dataList.add(canbo);
                    }
                    break;
                }
                case 2:
                    System.out.println("Nhap ten can bo can tim kiem: ");
                    String s = scan.nextLine();
                    
                    for (CanBo canBo : dataList) {
                        if(canBo.getFullname().equalsIgnoreCase(s)) {
                            canBo.display();
                        }
                    }
                    break;
                case 3: {
                    for (CanBo canBo : dataList) {
                        canBo.display();
                    }
                    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");
        System.out.println("2. Tim kiem theo ho ten");
        System.out.println("3. Hien thi thong tin");
        System.out.println("4. Thoat");
        System.out.println("Chon: ");
    }
}


#NhanVien.java


/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.gokisoft.lesson05.bt2270;

import java.util.Scanner;

/**
 *
 * @author diepvan
 */
public class NhanVien extends CanBo{
    String working;

    public NhanVien() {
    }

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

    public String getWorking() {
        return working;
    }

    public void setWorking(String working) {
        this.working = working;
    }
    
    public void input() {
        super.input();
        
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap cong viec: ");
        working = scan.nextLine();
    }

    @Override
    public String toString() {
        return super.toString() + ", working=" + working;
    }
    
    public void testNhanVien() {
        System.out.println("Test nhan vien...");
    }
}


Tags:



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

5

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

Đăng nhập để làm bài kiểm tra

Chưa có kết quả nào trước đó