员工案例增删改查

 

 

package employee;

import java.util.Scanner;

public class Test {
 Employee emp = new Employee();
 Scanner sc = new Scanner(System.in);

 Employee[] emps;

 public Test() {
  emps = new Employee[100];
 }

 public static void main(String[] args) {
  Test t = new Test();

  t.choose();

 }

 public void choose() {
  while (true) {
   start();
   int i = sc.nextInt();
   switch (i) {
   case 1:
    add();
    break;
   case 2:
    System.out.println("请输入要删除的姓名");
    String name = sc.next();
    delete(name);
    break;
   case 3:
    System.out.println("请修改要删除的姓名");
    String name1 = sc.next();
    modify(name1);
    break;

   case 4:
    System.out.println("请输入要查询的姓名");
    String name2 = sc.next();
    lookup(name2);
    break;
   case 5:
    System.out.println("退出系统");
    break;
   }

  }
 }

 public void add() {
  System.out.println("增加员工");
  System.out.println("请输入员工编号");
  String id = sc.next();
  System.out.println("请输入员工姓名");
  String name = sc.next();
  System.out.println("请输入职务(普通员工 经理 董事)");
  String post = sc.next();
  System.out.println("请输入请假天数");
  int leave = sc.nextInt();
  System.out.println("请输入基本工资");
  Double basicSalary = sc.nextDouble();
  if (post.equals("普通员工")) {
   Employee emp = new CommenEmployee(id, name, post, leave,
     basicSalary);
   for (int i = 0; i < emps.length; i++) {
    if (emp instanceof CommenEmployee) {
     CommenEmployee ce = (CommenEmployee) emp;
     if (emps[i] != ce) {
      emps[i] = ce;
      System.out.println("添加数据成功");
      ce.display();
      break;
     }
    }
   }

  } else if (post.equals("经理")) {
   Employee emp = new Manager(id, name, post, leave, basicSalary);
   for (int i = 0; i < emps.length; i++) {
    if (emp instanceof Manager) {
     Manager m = (Manager) emp;
     if (emps[i] != m) {
      emps[i] = m;
      System.out.println("添加数据成功");
      m.display();
      break;
     }
    }
   }

  } else if (post.equals("董事")) {
   Employee emp = new Director(id, name, post, leave, basicSalary);
   for (int i = 0; i < emps.length; i++)
    if (emp instanceof Director) {
     Director d = (Director) emp;
     if (emps[i] != d) {
      emps[i] = d;
      System.out.println("tia");
      d.display();
      break;
     }
    }
  }
 }

 public void delete(String name) {
  for (int i = 0; i < emps.length; i++) {
   if (emps[i].getName().equals(name)) {
    emps[i] = null;
    System.out.println("成功删除");
    break;

   } else {
    System.out.println("你要删除的用户不存在");
   }

  }

 }

 public void modify(String name) {
  for (int i = 0; i <= emps.length; i++) {
   if (emps[i] != null) {
    if (emps[i].getName().equals(name)) {
     emps[i].display();
     emps[i] = null;
     System.out.println("请重新输入");
     add();
     break;
    } else {
     System.out.println("你要修改的用户不存在");
    }
   }

  }
 }

 public void lookup(String name) {
  for (int i = 0; i <= emps.length; i++) {
   if (emps[i].getName().equals(name)) {
    emps[i].display();
break;
   } else {
    System.out.println("你要查询的用户不存在");

   }
  }

 }

 public void start() {
  System.out.println("1:增加");
  System.out.println("2:删除");
  System.out.println("3:修改");
  System.out.println("4:查询");
  System.out.println("5:退出");
  System.out.println("请选择业务");
 }
}

 

 

 

 

package employee;

public class CommenEmployee extends Employee {

 public CommenEmployee(){
  
 }
public CommenEmployee(String id,String name,String post,int leave,double basicSalary){
 super(id, name,post,leave,basicSalary);
}
 @Override
 public double sumSalary() {
return getbasicSalary()+getbasicSalary()*0.1+getbasicSalary()*0.5+200;

 }

 @Override
 public void display() {
  System.out.println("员工编号:"+this.getId()+"员工姓名:"+this.getName()+"员工职务:"+this.getPost()+"请假天数:"+
 this.getLeave()+"工资:"+sumSalary());
 }

}

 

 

package employee;

public class Director extends Employee {
 public Director(){
  
 }
 public Director(String id,String name,String post,int leave,double basicSalary){
  super(id, name,post,leave,basicSalary);
 }
 public double sumSalary() {
  return getbasicSalary()+getbasicSalary()*0.08+getbasicSalary()*0.3+5000; 
 
   }
 @Override
 
  public void display() {
   System.out.println("员工编号:"+this.getId()+"员工姓名:"+this.getName()+"员工职务:"+this.getPost()+"请假天数:"+
     this.getLeave()+"工资:"+sumSalary());  
  
 }
}

 

 

package employee;

public  class Employee {
 private String id;
 private String name;
 private String post;
 private int leave;
 private double basicSalary;
 public Employee(){
  super();
 }
 public Employee(String id,String name,String post,int leave,double basicSalary){
    this.id=id;
    this.name=name;
    this.post=post;
    this.leave=leave;
    this.basicSalary=basicSalary;
 }
 
 
 public String getId() {
  return id;
 }
 public void setId(String id) {
  this.id = id;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public String getPost() {
  return post;
 }
 public void setPost(String post) {
  this.post = post;
 }
 public int getLeave() {
  return leave;
 }
 public void setLeave(int leave) {
  this.leave = leave;
 }
 public double getbasicSalary() {
  return basicSalary;
 }
 public void setbasicSalary(double basicSalary) {
  this.basicSalary = basicSalary;
 }
 public double sumSalary(){
  return 0.0;
 }
 public   void display(){
  System.out.println("员工编号:"+getId()+"员工姓名:"+getName()+"员工职务:"+getPost()+"请假天数:"+
    getLeave()+"工资:"+sumSalary()); 
 };
 
}

 

 

package employee;

public class Manager extends Employee {
 public Manager(){
  
 }
 public  Manager(String id,String name,String post,int leave,double basicSalary){
  super(id, name,post,leave,basicSalary);
 }
 public double sumSalary() {
  
return getbasicSalary()+getbasicSalary()*0.2+getbasicSalary()*0.5+500;

   }
 @Override
 public void display() {
  System.out.println("员工编号:"+this.getId()+"员工姓名:"+this.getName()+"员工职务:"+this.getPost()+"请假天数:"+
    this.getLeave()+"工资:"+sumSalary());  
 }
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值