By GokiSoft.com|
15:14 21/06/2023|
Java Basic
[Share Code] Quản Lí Cán Bộ - C2209I
#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.c2209i.bt2270;
import java.util.Scanner;
/**
*
* @author teacher
*/
public class CanBo {
String fullname;
String birthday;
String gender;
String 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("Ngay gioi tinh: ");
gender = scan.nextLine();
System.out.println("Nhap dia chi: ");
address = scan.nextLine();
}
public void display() {
// System.out.format("\nHo ten: %s, ngay sinh: %s, gioi tinh: %s, dia chi: %s\n",
// fullname, birthday, gender, address);
System.out.println(toString());
// System.out.println(this);//param: object -> overloading -> object.toString()
}
@Override
public String toString() {
return "fullname=" + fullname + ", birthday=" + birthday + ", gender=" + gender + ", address=" + address;
}
}
#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.c2209i.bt2270;
import java.util.Scanner;
/**
*
* @author teacher
*/
public class CongNhan extends CanBo{
String bacLuong;
public CongNhan() {
}
public CongNhan(String bacLuong, String fullname, String birthday, String gender, String address) {
super(fullname, birthday, gender, address);
this.bacLuong = bacLuong;
}
public String getBacLuong() {
return bacLuong;
}
public void setBacLuong(String bacLuong) {
this.bacLuong = bacLuong;
}
@Override
public void input() {
super.input(); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/OverriddenMethodBody
Scanner scan = new Scanner(System.in);
System.out.println("Nhap bac luong: ");
bacLuong = scan.nextLine();
}
@Override
public String toString() {
return super.toString() + ", bacLuong=" + bacLuong;
}
}
#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.c2209i.bt2270;
import java.util.Scanner;
/**
*
* @author teacher
*/
public class KySu extends CanBo{
String nganhDaoTao;
public KySu() {
}
public String getNganhDaoTao() {
return nganhDaoTao;
}
public void setNganhDaoTao(String nganhDaoTao) {
this.nganhDaoTao = nganhDaoTao;
}
@Override
public void input() {
super.input(); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/OverriddenMethodBody
Scanner scan = new Scanner(System.in);
System.out.println("Nhap nganh dao tao: ");
nganhDaoTao = scan.nextLine();
}
@Override
public String toString() {
return super.toString() + ", nganhDaoTao=" + nganhDaoTao;
}
}
#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.c2209i.bt2270;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
*
* @author teacher
*/
public class Main {
public static void main(String[] args) {
// CongNhan cn = new CongNhan();
// cn.input();
// CongNhan cn = new CongNhan("Level 1", "TRAN VAN A",
// "NGAY SINH", "NAM", "HA NOI");
//T/c ke thua
// cn.display();
//bacLuong=Level 1
//fullname=TRAN VAN A, Birthday= ????
List<CanBo> dataList = new ArrayList<>();
Scanner scan = new Scanner(System.in);
int choose;
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());
CanBo canBo;
for (int i = 0; i < n; i++) {
showMenuCanBo();
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 tim kiem: ");
String findByName = scan.nextLine();
for (CanBo canBo : dataList) {
//canBo.getFullname() -> TRAN VAN DIEP
//findByName = Tran vAn Diep
//equalsIgnoreCase -> true
//equals -> false
if(canBo.getFullname().equalsIgnoreCase(findByName)) {
canBo.display();
}
}
}
break;
case 3: {
System.out.println("Thong tin can bo");
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 showMenuCanBo() {
System.out.println("1. Tao cong nha");
System.out.println("2. Tao ky su");
System.out.println("3. Tao nhan vien");
System.out.println("Chon: ");
}
static void showMenu() {
System.out.println("1. Nhap thong tin can bo");
System.out.println("2. Tim kiem & hien thi");
System.out.println("3. Hien thi");
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.c2209i.bt2270;
import java.util.Scanner;
/**
*
* @author teacher
*/
public class NhanVien extends CanBo{
String congViec;
public NhanVien() {
}
public String getCongViec() {
return congViec;
}
public void setCongViec(String congViec) {
this.congViec = congViec;
}
@Override
public void input() {
super.input(); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/OverriddenMethodBody
Scanner scan = new Scanner(System.in);
System.out.println("Nhap cong viec: ");
congViec = scan.nextLine();
}
@Override
public String toString() {
return super.toString() + ", congViec=" + congViec;
}
}
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)