Professional Documents
Culture Documents
Bài 2: 1. Doanh nghiệp
Bài 2: 1. Doanh nghiệp
Bài 2: 1. Doanh nghiệp
1. Doanh nghiệp
import java.util.Scanner;
2. IDoanhnghiep
/**
* IDoanhNghiep
*/
public interface IDoanhNghiep {
public void addNV();
public void editNV();
public int findByMaNV(int maNV);
public void sortByMaNV();
public void sortByPB();
public void displayMangNhanVien();
}
3. Nguoi
public abstract class Nguoi {
protected String firstName;
protected String lastName;
protected int age;
public Nguoi() {}
public Nguoi(String firstName, String lastName, int age){
this.age = age;
this.firstName = firstName;
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getFullname() {
return firstName + " " + lastName;
}
public abstract void add();
public abstract void display();
}
4. Nhân viên
import java.util.InputMismatchException;
import java.util.Scanner;
public class NhanVien extends Nguoi {
private int maNV;
private int pbNV;
public NhanVien(){}
public NhanVien(int maNV, String firstName, String lastName, int age, int pbNV) {
super(firstName, lastName, age);
this.maNV = maNV;
this.pbNV = pbNV;
}
public int getMaNV() {
return maNV;
}
public void setMaNV(int maNV) {
this.maNV = maNV;
}
public int getPbNV() {
return pbNV;
}
public void setPbNV(int pbNV) {
this.pbNV = pbNV;
}
public void add() {
Boolean done = false;
Scanner keyboard = new Scanner(System.in);
while (!done) {
try {
System.out.print("- Nhap ten:\n+ Ho: ");
firstName = keyboard.nextLine();
done = true;
} catch (InputMismatchException e) {
keyboard.nextLine();
System.out.println("Error: Invalid Ho");
}
}
done = false;
while (!done) {
try {
System.out.print("+ Ten: ");
lastName = keyboard.nextLine();
done = true;
} catch (InputMismatchException e) {
keyboard.nextLine();
System.out.println("Error: Invalid Ten");
}
}
done = false;
while (!done) {
try {
System.out.print("- Tuoi: ");
age = keyboard.nextInt();
done = true;
} catch (InputMismatchException e) {
keyboard.nextLine();
System.out.println("Error: Invalid Tuoi");
}
}
keyboard.nextLine();
done = false;
System.out.println("1. Ky thuat\n2. Ke toan\n3. Quan ly\n4. Ban hang");
while (!done) {
try {
System.out.print("- Phong ban: ");
pbNV = keyboard.nextInt();
if (pbNV > 4 || pbNV < 1) throw new Exception("Error: Invalid Phong ban");
done = true;
} catch (InputMismatchException e) {
keyboard.nextLine();
System.out.println("Error: Invalid Phong ban");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}