Java实现员工管理系统

作者:SleepException 时间:2023-04-10 23:44:44 

本文实例为大家分享了Java实现员工管理系统的具体代码,供大家参考,具体内容如下

本系统主要练习到的相关内容:

1、 流程控制语句
2、 类、对象
3、 封装、继承、多态
4、 方法的重载、重写
5、 访问修饰符
6、 static

需求说明:

员工信息的基本情况
—————————普通员工—————————–
属性:员工编号、员工姓名、员工职务、请假天数、基本工资
普通员工工资:
在基本工资的基础上增加10%的工作餐,50%的岗位补助,200元住房补助
基本工资+基本工资*0.1+基本工资*0.5+200
—————————–经理——————————–
属性:员工编号、员工姓名、员工职务、请假天数、基本工资
经理工资:
在基本工资的基础上增加20%的工作餐,50%的岗位补助,500元住房补助
基本工资+基本工资*0.2+基本工资*0.5+500
——————————-董事——————————–
属性:员工编号、员工姓名、员工职务、请假天数、基本工资
董事工资:
在基本工资的基础上增加8%的工作餐,30%的岗位补助,2000元住房补助,3000元投资补助
基本工资+基本工资*0.08+基本工资*0.3+2000+3000
——————————–其他———————————
工资扣除部分,所有员工都一样
无请假,基本工资全发,有请假,扣除每天平均工资 * 请假天数

大体设计思路:

Java实现员工管理系统

员工父类一个,普通员工,经理,董事长子类各一个,分别重写父类的工资方法。最后一个测试类。
实现后界面如图:

Java实现员工管理系统

父类子类的编写没什么问题,注意尽量做好封装,属性最好用private修饰。小编偷了个懒,主要把时间用在测试类的编写上o( ̄ε ̄*)o。
注意:由于本系统只是将对象存于对象数组,数组初始化时定长设定为100,系统会自动初始化每个数组元素为null,所以在写测试类的方法时一定注意写好判断预防遍历赋值发生的空指针错误,小编比较笨,所以饶了好一会才写出来(¬_¬)
还有就是如果更改员工的资料时注意,若是员工的职位发生变化该怎么处理,毕竟对象变了,处理工资的方法也不一样。

以下贴出代码:

首先是父类Employee


//父类
public class Employee {
String ID;
String name;
String position;
int holiday;
double salary;
public Employee(){}
public void sumSalary(){}
public void display(){
 System.out.println("ID:"+ID+",姓名:"+name+",职位:"+position+",请假天数:"+holiday+",工资:"+salary);
}
}

三个子类:


public class CommonEmployee extends Employee{
@Override
public void sumSalary(){
 super.salary=super.salary+super.salary*0.1+super.salary*0.5+200-super.holiday*(super.salary/30);
}
}
public class Manager extends Employee{
@Override
public void sumSalary(){
 super.salary=super.salary+super.salary*0.2+super.salary*0.5+200-super.holiday*(super.salary/30);
}
}
public class Director extends Employee{
@Override
public void sumSalary(){
 super.salary=super.salary+super.salary*0.08+super.salary*0.3+2000+3000-super.holiday*(super.salary/30);
}
}

接下来就是关键的测试类,这里完成增删改查== 有点多。


public class TestEMD {
static Scanner sc = new Scanner(System.in);
static Employee[] em = new Employee[100];

public static void caoZuo() {
 System.out.println("----  工资管理系统     ----");
 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("-------------------------------");
 System.out.println("请输入你要选择的操作:");
 Scanner sc = new Scanner(System.in);
 String s = sc.next();
 switch (s) {
 case "1":
  addEmployee();
  break;
 case "2":
  delEmployee();
  break;
 case "3":
  updateEmployee();
  break;
 case "4":
  queryEmployee();
  break;
 case "0":
  System.out.println("谢谢使用O(∩_∩)O");
  break;
 default:
  System.out.println("指令错误请重新输入!");
  caoZuo();
  break;
 }
}

public static void addEmployee() {
 System.out.println("------增加员工------");
 System.out.println("请输入相关信息:");
 System.out.print("ID:");
 String id = sc.next();
 System.out.print("姓名:");
 String name = sc.next();
 System.out.print("职务:");
 String position = sc.next();
 System.out.print("请假天数:");
 int holiday = sc.nextInt();
 System.out.print("基本工资:");
 double salary = sc.nextDouble();
 switch (position) {
 case "普通员工":
  Employee a = new CommonEmployee();
  a.ID = id;
  a.name = name;
  a.position = "普通员工";
  a.holiday = holiday;
  a.salary = salary;
  a.sumSalary();
  for (int i = 0; i < 100; i++) {
   if (em[i] == null) {
    em[i] = a;
    System.out.println("添加成功!");
    em[i].display();
    break;
   } else {
    continue;
   }
  }
  break;
 case "经理":
  Employee b = new Manager();
  b.ID = id;
  b.name = name;
  b.position = "经理";
  b.holiday = holiday;
  b.salary = salary;
  b.sumSalary();
  for (int i = 0; i < 100; i++) {
   if (em[i] == null) {
    em[i] = b;
    System.out.println("添加成功!");
    em[i].display();
    break;
   } else {
    continue;
   }
  }
  break;
 case "董事长":
  Employee c = new Director();
  c.ID = id;
  c.name = name;
  c.position = "董事长";
  c.holiday = holiday;
  c.salary = salary;
  c.sumSalary();
  for (int i = 0; i < 100; i++) {
   if (em[i] == null) {
    em[i] = c;
    System.out.println("添加成功!");
    em[i].display();
    break;
   } else {
    continue;
   }
  }
  break;
 default:
  System.out.println("不存在此职务,请重新输入!");
  addEmployee();
  break;
 }
 caoZuo();
}

public static void delEmployee() {
 System.out.println("----------删除员工---------");
 System.out.println("请输入员工姓名:");
 String n = sc.next();
 for (int i = 0; i < 100; i++) {
  if (em[i] != null) {
   if (em[i].name.equals(n)) {
    System.out.println("你要删除的是:" + em[i].toString());
    System.out.println("你确定要删除吗?\n [Y]确定,[N]取消");
    String s = sc.next();
    if (s.equals("y")) {
     em[i] = null;
     System.out.println("删除成功!");
     try {
      Thread.sleep(2000);
     } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     }
     caoZuo();
    } else if (s.equals("n")) {
     caoZuo();
    } else {
     System.out.println("输入指令不正确,请重新输入!");
     delEmployee();
    }
   } else {
    if (i != 99) {
     continue;
    } else {
     System.out.println("你输入的账号不存在!请重新输入!");
     delEmployee();
    }

}
  } else {
   if (i != 99) {
    continue;
   } else {
    System.out.println("你输入的账号不存在!请重新输入!");
    delEmployee();
   }
  }
 }
}

public static void updateEmployee() {
 System.out.println("--------------修改员工资料-------------");
 System.out.println("请输入你要修改的姓名:");
 String s = sc.next();
 out: for (int i = 0; i < 100; i++) {
  if (em[i] != null) {
   if (em[i].name.equals(s)) {
    System.out.println("你要修改的是:");
    em[i].display();
    System.out.println("请重新输入相关信息:");
    System.out.print("ID:");
    String id = sc.next();
    System.out.print("姓名:");
    String name = sc.next();
    System.out.print("职务:");
    String position = sc.next();
    System.out.print("请假天数:");
    int holiday = sc.nextInt();
    System.out.print("基本工资:");
    double salary = sc.nextDouble();
    switch (position) {
    case "普通员工":
     if (em[i].position.equals("普通员工")) {
      em[i].ID = id;
      em[i].name = name;
      em[i].position = position;
      em[i].holiday = holiday;
      em[i].salary = salary;
      em[i].sumSalary();
      System.out.println("修改成功!");
      em[i].display();
     } else {
      em[i] = null;
      Employee a = new CommonEmployee();
      a.ID = id;
      a.name = name;
      a.position = "普通员工";
      a.holiday = holiday;
      a.salary = salary;
      a.sumSalary();
      for (int j = 0; j < 100; j++) {
       if (em[j] == null) {
        em[j] = a;
        System.out.println("修改成功!");
        em[j].display();
        break;
       } else {
        continue;
       }
      }
     }
     break;
    case "经理":
     if (em[i].position.equals("经理")) {
      em[i].ID = id;
      em[i].name = name;
      em[i].position = position;
      em[i].holiday = holiday;
      em[i].salary = salary;
      em[i].sumSalary();
      System.out.println("修改成功!");
      em[i].display();
     } else {
      em[i] = null;
      Employee b = new Manager();
      b.ID = id;
      b.name = name;
      b.position = "经理";
      b.holiday = holiday;
      b.salary = salary;
      b.sumSalary();
      for (int j = 0; j < 100; j++) {
       if (em[j] == null) {
        em[j] = b;
        System.out.println("修改成功!");
        em[j].display();
        break;
       } else {
        continue;
       }
      }
     }
     break;
    case "董事长":
     if (em[i].position.equals("董事长")) {
      em[i].ID = id;
      em[i].name = name;
      em[i].position = position;
      em[i].holiday = holiday;
      em[i].salary = salary;
      em[i].sumSalary();
      System.out.println("修改成功!");
      em[i].display();
     } else {
      em[i] = null;
      Employee c = new Director();
      c.ID = id;
      c.name = name;
      c.position = "董事长";
      c.holiday = holiday;
      c.salary = salary;
      c.sumSalary();
      for (int j = 0; j < 100; j++) {
       if (em[j] == null) {
        em[j] = c;
        System.out.println("添加成功!");
        em[j].display();
        break;
       } else {
        continue;
       }
      }
     }
     break;
    default:
     System.out.println("不存在此职务,请重新输入!");
     addEmployee();
     break;
    }

try {
     Thread.sleep(2000);
    } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
    caoZuo();
   } else {
    if (i != 99) {
     continue out;
    } else {
     System.out.println("你输入的员工不存在!请重新输入!");
     caoZuo();
    }
   }
  } else {
   if (i != 99) {
    continue out;
   } else {
    System.out.println("你输入的员工不存在!请重新输入!");
    caoZuo();
   }
  }
 }
}

public static void queryEmployee() {
 System.out.println("--------------所有员工信息---------------");
 for (int i = 0; i < 100; i++) {
  if (em[i] != null) {
   em[i].display();
  }
 }
 try {
  Thread.sleep(2000);
 } catch (InterruptedException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
 caoZuo();
}

public static void main(String[] args) {
 // TODO Auto-generated method stub
 TestEMD.caoZuo();
}

}

程序刚写完就来发帖了,简单测试并未发现什么问题,若是大家发现有什么不对的欢迎指正,谢谢啦。

更多学习资料请关注专题《管理系统开发》。

来源:http://blog.csdn.net/hahaha_sxm/article/details/48169711

标签:java,管理系统
0
投稿

猜你喜欢

  • Android 连接Wifi和创建Wifi热点的实例

    2022-07-16 06:00:52
  • Android仿知乎悬浮功能按钮FloatingActionButton效果

    2021-08-04 16:33:47
  • SpringMVC 上传文件 MultipartFile 转为 File的方法

    2021-07-06 00:28:12
  • struts2中使用注解配置Action方法详解

    2023-08-30 00:01:25
  • Java内存模型详解

    2023-06-21 21:04:29
  • Java使用动态规划算法思想解决背包问题

    2022-12-02 03:53:49
  • Android实现下拉展示条目效果

    2021-09-29 21:00:42
  • Android开发学习笔记之通过API接口将LaTex数学函数表达式转化为图片形式

    2023-02-28 06:50:24
  • Java并发编程之线程之间的共享和协作

    2021-07-20 14:28:27
  • 详解C#读取Appconfig中自定义的节点

    2022-07-16 08:30:38
  • 举例讲解Java编程中this关键字与super关键字的用法

    2023-03-09 01:46:02
  • java不同版本在多线程中使用随机数生成器的实现

    2022-01-02 22:57:07
  • java代码实现MD5加密及验证过程详解

    2023-09-26 02:50:45
  • C#读取word中表格数据的方法实现

    2023-09-12 22:54:53
  • 深入了解java.util.Arrays的使用技巧

    2023-01-10 18:01:32
  • 一文了解自定义MVC框架实现

    2023-01-11 00:15:10
  • Java实现验证码的产生和验证

    2022-10-30 22:41:39
  • JAVA中实现链式操作(方法链)的简单例子

    2022-12-16 00:54:50
  • Java中对话框的弹出方法

    2022-04-24 14:35:52
  • SpringMVC中MultipartFile转File的两种方式

    2023-08-18 20:25:00
  • asp之家 软件编程 m.aspxhome.com