基于Java的简单的企业员工管理系统,供大家参考,具体内容如下
首先创建了一个员工类
定义员工应有的属性:工号、姓名、性别、职位、年龄、工资、部门
1
2
3
4
5
6
7
8
|
/** 员工属性 */ private int sno; //工号 private String name; //姓名 private String sex; //性别 private String job; //职位 private int age; //年龄 private int money; //工资 private String section; //部门 |
用eclipse快捷键Alt+s/快速生成与其属性get/set方法与Constructor构造器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
public Emp( int sno, String name, String sex, String job, int age, int money, String section) { this .sno = sno; this .name = name; this .sex = sex; this .job = job; this .age = age; this .money=money; this .section = section; } public int getSno() { return sno; } public void setSno( int sno) { this .sno = sno; } public String getName() { return name; } public void setName(String name) { this .name = name; } public String getSex() { return sex; } public void setSex(String sex) { this .sex = sex; } public String getJob() { return job; } public void setJob(String job) { this .job = job; } public int getAge() { return age; } public void setAge( int age) { this .age = age; } public int getMoney() { return money; } public void setMoney( int money) { this .money = money; } public String getSection() { return section; } public void setSection(String section) { this .section = section; } |
这样很轻松的就能完成一个员工类的基本属性
然后在新建的类中完成对员工属性的进行实现的方法
通过构造器与方法来实现对员工信息的输出,员工的各个属性通过多个方法去完成。
我这里定义一个指定长度的数组,再通过方法来扩大它的容量。
1
2
3
4
5
6
7
|
Emp[] list = new Emp[ 10 ]; /** 初始化数组的索引 */ public int index = 0 ; public void add(Emp s) { list[index++] = s; } |
通过方法能够输出员工的属性
1
2
3
4
5
6
7
8
9
10
11
12
13
|
/**对员工信息的输出*/ public void listStu() { System.out.println( "公民信息:" + "\t" + "工号" + "\t" + "姓名" + "\t" + "性别" + "\t" + "职位" + "\t" + "年龄" + "\t" + "工资" + "\t" + "部门" ); for (Emp s : list) { if (s != null ) { System.out.println( "\t" + s.getSno() + "\t" + s.getName() + "\t" + s.getSex() + "\t" + s.getJob() + "\t" + s.getAge() + "\t" + s.getMoney() + "\t" + s.getSection()); } } System.out.println(); } |
实现通过工号对员工进行查询、修改和删除等操作
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
/** 根据工号查询员工信息 */ public Emp findBySno( int sno) { for (Emp s : list) { if (s != null && s.getSno() == sno) { System.out.println( s.getName() + "/" + s.getSex() + "/" + s.getJob() + "/" + s.getMoney() + "/" + s.getSection()); System.out.println(); return s; } } return null ; } /** 根据工号更改工资 */ public void updata( int sno, int money) { // 1.查询出指定工号的员工 Emp s = this .findBySno(sno); if (s != null ) { s.setMoney(money); System.out.println( "您更改员工信息如下:" ); System.out.println( s.getName() + "/" + s.getSex() + "/" + s.getJob() + "/" + s.getMoney() + "/" + s.getSection()); } } /** 移除数组中指定位置元素 */ public Emp remove( int sno) { // 获取需要被移除的元素 for ( int i = 0 ; i < list.length; i++) { Emp emp = list[i]; if (emp != null && emp.getSno() == sno) { sno = i; //找到数组中sno(工号)对应的位置并且将此地址号赋给sno(工号) } } /**将找到的sno(工号)对应位置用来查找*/ Emp s = list[sno]; //此时sno(工号)已经换成对应数组中的位置 // 将目标位置的元素置为0 list[sno] = null ; System.arraycopy(list, sno, list, sno + 1 , list.length - (sno + 1 )); // 索引相应减少 index--; // 将被删除的元素返回 listStu(); return s; } |
这些就是对于员工信息进行修饰和条件判断的代码
最后创建一个类来对以上信息进行输出
这个类通过对象来调用其他类的方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
// 工号 姓名 性别 职位 年龄 工资 部门 // sno name sex job age money section Emp s1 = new Emp( 101 , "Tryci" , "男" , "部门经理" , 23 , 8888 , "Java" ); Emp s2 = new Emp( 102 , "张三" , "男" , "项目经理" , 21 , 7777 , "C++" ); Emp s3 = new Emp( 103 , "李四" , "男" , "部门经理" , 25 , 6666 , "前端" ); Emp s4 = new Emp( 104 , "王五" , "男" , "项目经理" , 24 , 5555 , "Java" ); Emp s5 = new Emp( 105 , "赵六" , "男" , "清洁人员" , 22 , 4444 , "卫生" ); Principal sm = new Principal(); sm.add(s1); sm.add(s2); sm.add(s3); sm.add(s4); sm.add(s5); sm.listStu(); // 根据工号查询员工信息? System.out.print( "您查询员工信息: " ); sm.findBySno( 101 ); // 将学号为104的学生的工资更改 sm.updata( 104 , 6666 ); // 删除数组中第某个元素 sm.remove( 102 ); |
虽然这样完成了一个基本的员工信息管理系统,但是包含的内容与方法技术含量很低,也不能通过控制台等操作来对信息进行录入和修改.
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_36298311/article/details/96468631