//普通员工类
public class commonEmployee extends Employee {
public commonEmployee(String ID, String name, String position, int holiday,
double salary) {
super(ID, name, position, holiday, salary);
// TODO Auto-generated constructor stub
}
public double sumSalary(double salary) {
salary=salary+salary*0.1+salary*0.5+200.0;
salary=salary-salary/30*holiday;
return salary;
}
}
//经理类
public class Manager extends Employee {
public Manager(String ID, String name, String position, int holiday,
double salary) {
super(ID, name, position, holiday, salary);
// TODO Auto-generated constructor stub
}
public double sumSalary(double salary){
salary=salary+salary*0.2+salary*0.5+500.0;
salary=salary-salary/30*holiday;
return salary;
}
}
//董事长类
public class Director extends Employee {
public Director(String ID, String name, String position, int holiday,
double salary) {
super(ID, name, position, holiday, salary);
// TODO Auto-generated constructor stub
}
public double sumSalary(double salary){
salary=salary+salary *0.08+salary *0.3+5000.0;
salary=salary-salary/30*holiday;
return salary;
}
}
//员工类(父类)
package 员工管理;
import java.util.Scanner;
/*import com.sun.javafx.scene.paint.GradientUtils.Point;
import com.sun.org.apache.regexp.internal.recompile;*/
class Employee {
String ID;
String name;
String position;
int holiday;
double salary;
public Employee(String ID,String name,String position,int holiday,double salary){
this.ID=ID;
this.name=name;
this.position=position;
this.holiday=holiday;
this.salary=salary;
}
public void display(Employee e){
System.out.println("编号:"+e.getID()+" 姓名:"+e.getName()+" 职务:"+e.getPosition()+" 请假天数:"+e.getHoliday()+" 工资:"+e.getSalary());
}
public String getID() {
return ID;
}
public void setID(String iD) {
ID = iD;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public int getHoliday() {
return holiday;
}
public void setHoliday(int holiday) {
this.holiday = holiday;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
//增加
public Employee []addEmployee(Employee[]t){
int i=t.length+1;
Employee [] ems=new Employee[i];
System.arraycopy(t, 0, ems, 0, i-1);
System.out.println("请输入员工编号:");
Scanner scanner=new Scanner(System.in);
ID=scanner.next();
System.out.println("请输入员工姓名:");
name=scanner.next();
System.out.println("请输入员工职务(普通员工,经理,董事长)");
position=scanner.next();
if(position.equals("普通员工")||position.equals("经理")||position.equals("董事长"));
else {
System.out.println("没有该职位,请重新输入");
position=scanner.next();
}
System.out.println("请输入员工请假天数:");
holiday =scanner.nextInt();
System.out.println("请输入员工基本工资:");
salary=scanner.nextDouble();
Employee e1=new Employee(ID,name,position,holiday,salary);
//判断职位
if("普通员工".equals(position)){
commonEmployee c1=new commonEmployee(e1.getID(), e1.getName(), e1.getPosition(), e1.getHoliday(), e1.getSalary());
salary=c1.sumSalary(c1.getSalary());
e1.setSalary(salary);
}
if("经理".equals(position)){
Manager c1=new Manager(e1.getID(), e1.getName(), e1.getPosition(), e1.getHoliday(), e1.getSalary());
salary=c1.sumSalary(c1.getSalary());
e1.setSalary(salary);
}
if("董事长".equals(position)){
Director c1=new Director(e1.getID(), e1.getName(), e1.getPosition(), e1.getHoliday(), e1.getSalary());
salary=c1.sumSalary(c1.getSalary());
e1.setSalary(salary);
}
ems[i-1]=e1;
e1.display(e1);
System.out.println("添加成功!");
return ems;
}
//查询全部
public void search(Employee[]ems){
for (int i = 0; i < ems.length; i++) {
Employee ee=ems[i];
ee.display(ee);
}
}
//按姓名查询
public void queryEmployee(Employee[]ems,String name){
for (int i = 0; i < ems.length; i++) {
Employee e1=ems[i];
if(e1.getName().equals(name)){
e1.display(e1);
}
}
}
//删除员工
public Employee[] delEmployee(Employee[]t,String name){
int i=t.length-1;
Employee[]ems=new Employee[i];
for (int j = 0; j < t.length; j++) {
Employee e1=t[j];
if(e1.getName().equals(name)){
System.arraycopy(t, 0, ems, 0, j);
System.arraycopy(t, j+1, ems, j, ems.length-j);
System.out.println("删除数据成功");
}
}
return ems;
}
//修改员工信息
public Employee[] updateEmployee(Employee[]ems,String name){
for (int i = 0; i < ems.length; i++) {
Employee e1=ems[i];
if(e1.getName().equals(name)){
System.out.println("请重新输入员工信息!");
System.out.println("请输入员工编号:");
Scanner scanner=new Scanner(System.in);
ID=scanner.next();
System.out.println("请输入员工姓名:");
String name0=scanner.next();
System.out.println("请输入员工职务(普通员工,经理,董事长)");
position=scanner.next();
if(position.equals("普通员工")||position.equals("经理")||position.equals("董事长"));
else {
System.out.println("没有该职位,请重新输入");
position=scanner.next();
}
System.out.println("请输入员工请假天数:");
holiday =scanner.nextInt();
System.out.println("请输入员工基本工资:");
salary=scanner.nextDouble();
Employee e2=new Employee(ID, name0, position, holiday, salary);
//判断职位
if("普通员工".equals(position)){
commonEmployee c1=new commonEmployee(e2.getID(), e2.getName(), e2.getPosition(), e2.getHoliday(), e2.getSalary());
salary=c1.sumSalary(c1.getSalary());
e2.setSalary(salary);
}
if("经理".equals(position)){
Manager c1=new Manager(e2.getID(), e2.getName(), e2.getPosition(), e2.getHoliday(), e2.getSalary());
salary=c1.sumSalary(c1.getSalary());
e2.setSalary(salary);
}
if("董事长".equals(position)){
Director c1=new Director(e2.getID(), e2.getName(), e2.getPosition(), e2.getHoliday(), e2.getSalary());
salary=c1.sumSalary(c1.getSalary());
e2.setSalary(salary);
}
ems[i]=e2;
e2.display(e2);
System.out.println("修改成功!");
}
}
return ems;
}
}
//test类
import java.util.Scanner;
public class TestEmployeeManage {
public static void main(String[] args) {
// TODO Auto-generated method stub
Employee[] ems = new Employee[0];
Employee e1 = new Employee("ID", "name", "position", 1, 1);
while (true) {
System.out.println("|----------------------------|");
System.out.println("|---------1 增加--------|");
System.out.println("|---------2 删除--------|");
System.out.println("|---------3 修改--------|");
System.out.println("|---------4 查询--------|");
System.out.println("|---------0 退出--------|");
System.out.println("|----------------------------|");
Scanner sc = new Scanner(System.in);
int caozuo = sc.nextInt();
switch (caozuo) {
case 1:
ems = e1.addEmployee(ems);
break;
case 2:
System.out.println("请输入要删除的员工姓名:");
String name1=sc.next();
ems=e1.delEmployee(ems, name1);
break;
case 3:
System.out.println("请输入要修改的员工姓名:");
String name2=sc.next();
ems=e1.updateEmployee(ems, name2);
break;
case 5:
e1.search(ems);
break;
case 4:
System.out.println("请输入员工姓名:");
String name3=sc.next();
e1.queryEmployee(ems, name3);
break;
default:
System.exit(0);
}
}
}
}