Created
April 11, 2012 18:56
-
-
Save ngnguyen1/2361383 to your computer and use it in GitHub Desktop.
Quản lý cán bộ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************** | |
author: nduy.nga | |
*********************/ | |
package QLy; | |
public class CanBo | |
{ | |
private String sHoTen,sGioiTinh,sDiaChi; | |
private int iNamSinh; | |
//Toan tu tao lap | |
CanBo() | |
{} | |
CanBo(String shoten,String sgioitinh,String sdiachi,int inamsinh) | |
{ | |
this.sHoTen = shoten; | |
this.sGioiTinh = sgioitinh; | |
this.sDiaChi = sdiachi; | |
this.iNamSinh = inamsinh; | |
} | |
public void InputData() | |
{ | |
System.out.print("Nhap Ho Ten :");this.sHoTen=NhapDL.nhapchuoi(); | |
System.out.print("Nhap Gioi Tinh :");this.sGioiTinh=NhapDL.nhapchuoi(); | |
System.out.print("Nhap Dia Chi :");this.sDiaChi=NhapDL.nhapchuoi(); | |
System.out.print("Nhap Nam Sinh :");this.iNamSinh=NhapDL.nhapInt(); | |
} | |
// Hien thi thong tin can bo | |
public void OutputData() | |
{ | |
System.out.println("Ho ten :" +this.sHoTen); | |
System.out.println("Gioi Tinh :" +this.sGioiTinh); | |
System.out.println("Dia Chi :" +this.sDiaChi); | |
System.out.println("Nam sinh :" +this.iNamSinh); | |
} | |
public boolean TimKiem(String sKeyWord) | |
{ | |
StringBuffer st = new StringBuffer(this.sHoTen); | |
if(st.lastIndexOf(sKeyWord)>=0) | |
return true; | |
else | |
return false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************** | |
author: nduy.nga | |
*********************/ | |
package QLy; | |
public class CongNhan extends CanBo | |
{ | |
private String sBac; | |
public CongNhan() | |
{ | |
} | |
CongNhan(String Bac) | |
{ | |
this.sBac=Bac; | |
} | |
// Ham nhap thong tin dc ghi de | |
public void InputData() | |
{ | |
super.InputData(); | |
System.out.print("Nhap cap bac :");this.sBac=NhapDL.nhapchuoi(); | |
} | |
public void OutputData() | |
{ | |
super.OutputData(); | |
System.out.println("Bac CN :" +this.sBac); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************** | |
author: nduy.nga | |
*********************/ | |
package QLy; | |
public class KySu extends CanBo | |
{ | |
private String sNganh; | |
public KySu() | |
{} | |
public KySu(String snganh) | |
{ | |
this.sNganh=snganh; | |
} | |
public void InputData() | |
{ | |
super.InputData(); | |
; | |
System.out.print("Nhap Nganh :");this.sNganh=NhapDL.nhapchuoi(); | |
} | |
public void OutputData() | |
{ | |
super.OutputData(); | |
System.out.println("Nganh :" +this.sNganh); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************** | |
author: nduy.nga | |
*********************/ | |
package QLy; | |
public class NhanVien extends CanBo | |
{ | |
private String sCongViec; | |
public NhanVien() | |
{} | |
public NhanVien(String scongviec) | |
{ | |
this.sCongViec=scongviec; | |
} | |
public void InputData() | |
{ | |
super.InputData(); | |
System.out.print("Nhap cong viec :");this.sCongViec=NhapDL.nhapchuoi(); | |
} | |
public void OutputData() | |
{ | |
super.OutputData(); | |
System.out.println("Cong viec la :" +this.sCongViec); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************** | |
author: nduy.nga | |
*********************/ | |
package QLy; | |
import java.io.*; | |
public class NhapDL | |
{ | |
static DataInputStream str=new DataInputStream(System.in); | |
public static String nhapchuoi() | |
{ | |
String st=""; | |
try { | |
st=str.readLine(); | |
}catch(Exception e){ | |
System.out.println("Loi" +e); | |
} | |
return st; | |
} | |
public static int nhapInt() | |
{ | |
String st=NhapDL.nhapchuoi(); | |
int i=0; | |
try{ | |
i=Integer.valueOf(st).intValue(); | |
}catch(Exception e){ | |
System.out.println("Loi" +e); | |
} | |
return i; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************** | |
author: nduy.nga | |
******************/ | |
import java.util.*; | |
import QLy.*; | |
public class QLyCanBo | |
{ | |
public static void main(String[] args) | |
{ | |
CanBo[] dsCB = null; | |
int iLuaChon=-1,n=0; | |
while(iLuaChon!=5) | |
{ | |
System.out.println("||===============================||"); | |
System.out.println("|| Chuong Trinh QLy Can Bo ||"); | |
System.out.println("|| 1. Nhap Thong Tin moi n CBo ||"); | |
System.out.println("|| 2. Tim kiem theo ho ten ||"); | |
System.out.println("|| 3. Hien thi thong tin ve dsCB ||"); | |
System.out.println("|| 4. Hien thi theo loai Can Bo ||"); | |
System.out.println("|| 5. Thoat khoi chuong trinh ||"); | |
System.out.println("||===============================||"); | |
System.out.print("Nhap lua chon cua ban: "); | |
iLuaChon=NhapDL.nhapInt(); | |
switch(iLuaChon) | |
{ | |
case 1:{ | |
System.out.print("Ban muon nhap bao nhieu can bo? ");n = NhapDL.nhapInt(); | |
dsCB = new CanBo[n]; | |
for(int i=0;i<n;i++){ | |
System.out.println("Nhap vao thong tin cho can bo thu " +(i+1)); | |
boolean ok=false; | |
while(!ok){ | |
System.out.print("Nhap loai can bo CN,KS,NV: "); | |
String sLoaiCB = NhapDL.nhapchuoi().trim(); | |
if(sLoaiCB.equalsIgnoreCase("cn")) | |
{ | |
dsCB[i]=new CongNhan(); | |
dsCB[i].InputData(); | |
ok=true; | |
}else | |
if(sLoaiCB.equalsIgnoreCase("ks")) | |
{ | |
dsCB[i]=new KySu(); | |
dsCB[i].InputData(); | |
ok=true; | |
}else | |
if(sLoaiCB.equalsIgnoreCase("nv")) | |
{ | |
dsCB[i] = new NhanVien(); | |
dsCB[i].InputData(); | |
ok=true; | |
} | |
} | |
} | |
System.out.println("Da nhap xong . . . ."); | |
break; | |
} | |
case 2:{ | |
if(dsCB!=null) | |
{ | |
System.out.print("Nhap tu khoa: "); | |
String sKey = NhapDL.nhapchuoi().trim(); | |
StringTokenizer st2=new StringTokenizer(sKey," ",false); | |
System.out.println("Ket qua tim kiem: "); | |
for(int i=0;i<n;i++) | |
if(dsCB[i].TimKiem(st2.nextToken()) || (st2.hasMoreTokens())) | |
{ | |
dsCB[i].OutputData(); | |
} | |
System.out.println("Tim xong!!"); | |
} | |
else | |
System.out.println("Canh bao: Ban chua nhap danh sach!!"); | |
break; | |
} | |
case 3:{ | |
if(dsCB!=null) | |
{ | |
System.out.println("Danh sach can bo la:"); | |
for(int i=0;i<n;i++){ | |
dsCB[i].OutputData(); | |
} | |
} | |
else{ | |
System.out.println("Ban chua nhap ds can bo!!!"); | |
} | |
break; | |
} | |
case 4:{ | |
if(dsCB!=null){ | |
System.out.print("Nhap vao loai can bo congnhan,nhanvien,kysu: "); | |
String st=NhapDL.nhapchuoi(); | |
for(int i=0;i<n;i++){ | |
if(dsCB[i].getClass().getName().equalsIgnoreCase("QLy."+st)) | |
dsCB[i].OutputData(); | |
} | |
}else{ | |
System.out.println("Ban chua nhap DS!!"); | |
} | |
break; | |
} | |
case 5:{ | |
System.out.println("GoodBye. See You Again!!!"); | |
break; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment