员工管理系统要求如下:
通过面向对象的编程思想,实现员工信息的增删改查,存储结构为数组。限定数组长度为100。
实现页面:
添加员工
查找员工
修改员工
删除员工、退出
工程目录结构:
1.employee基类
?
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/**
* @author 李广亮
*
*/
public class employee {
/**
* 成员属性:id、姓名、职务、请假天数、基本工资
*/
private string id;
private string name;
private string job;
private int holiday;
private double salary;
/**
* 计算工资
*/
public double sunsalary( double salary, int holiday) {
return salary - (salary/ 30 ) * holiday;
}
/**
* get和set方法
*/
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 getjob() {
return job;
}
public void setjob(string job) {
this .job = job;
}
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;
}
/**
* tostring()方法
*/
public string tostring() {
return "编号:" + id + ", 姓名:" + name + ", 职务" + job
+ ", 请假天数:" + holiday + ", 工资:" + salary;
}
}
|
2.普通员工类commonemployee
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
public class commonemployee extends employee {
/**
* 普通员工工资
* 在基本工资的基础上增加10%的工作餐,50%的岗位补助,200元住房补助
* @param 工资
* @param 请假天数
*/
@override
public double sunsalary( double salary, int holiday) {
double sum = salary + salary* 0.1 + salary* 0.5 + 200 ;
return sum - sum/ 30 * holiday;
}
}
|
3.经理manageremployee
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
public class manageremployee extends employee {
/**
* 经理工资
* 在基本工资的基础上增加20%的工作餐,50%的岗位补助,500元住房补助
* @param 工资
* @param 请假天数
*/
@override
public double sunsalary( double salary, int holiday) {
double sum = salary + salary* 0.2 + salary* 0.5 + 500 ;
return sum - sum/ 30 * holiday;
}
}
|
4.懂事directoremployee
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
public class manageremployee extends employee {
/**
* 经理工资
* 在基本工资的基础上增加20%的工作餐,50%的岗位补助,500元住房补助
* @param 工资
* @param 请假天数
*/
@override
public double sunsalary( double salary, int holiday) {
double sum = salary + salary* 0.2 + salary* 0.5 + 500 ;
return sum - sum/ 30 * holiday;
}
}
|
5.业务逻辑类testemd
?
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
/**
* @author 李广亮
*
*/
public class testemd {
/**
* len代表数组的当前下标
*/
static int len = - 1 ;
static employee[] emp = new employee[ 100 ];
static scanner sc = new scanner(system.in);
/**
* 增加新雇员
*/
public void addemployee() {
employee em = null ;
system.out.println( "---增加员工---" );
system.out.print( "请输入员工编号:" );
string id = sc.next();
system.out.print( "请输入员工姓名:" );
string name = sc.next();
system.out.print( "请输入员工职务(员工、经理、懂事):" );
string job = sc.next();
system.out.print( "请输入员工请假天数:" );
int holiday = sc.nextint();
system.out.print( "请输入员工基本工资:" );
double salary = sc.nextdouble();
//在此作一下逻辑判断,根据job的不同,创建不同的employee子类
if (job.equals( "员工" )) {
em = new commonemployee();
} else if (job.equals( "经理" )) {
em = new manageremployee();
} else if (job.equals( "懂事" )) {
em = new directoremployee();
} else {
system.out.println( "输入不正确!" );
}
em.setid(id);
em.setname(name);
em.setjob(job);
em.setholiday(holiday);
em.setsalary(salary);
//len先加1后使用,变为emp[0]
emp[++len] = em;
printemployee(emp[len]);
system.out.println( "添加成功!" );
}
/**
* 删除员工
*/
public void deleteemployee() {
system.out.println( "------删除员工------" );
system.out.println( "---请输入员工姓名:---" );
//设置一个boolean类型的flg标志,若查找不到则为false
boolean flg = false ;
string name = sc.next();
for ( int i= 0 ; i<=len; i++) {
//若查找成功,则把emp[i]数组后面的指针往前移一位,覆盖掉当前的指向对象
if (emp[i].getname().equals(name)) {
printemployee(emp[i]);
for ( int j=i; j<=len; j++) {
emp[j] = emp[j+ 1 ];
}
//前移后,最后一位置空,len--
emp[len] = null ;
len--;
system.out.println( "删除成功!" );
flg = true ;
break ;
}
}
if (!flg) {
system.out.println( "查无此人,请重新输入:" );
deleteemployee();
}
}
/**
* 修改雇员信息
* @param args
* @return
*/
public void updateemployee() {
system.out.println( "------修改员工------" );
system.out.println( "---请输入员工姓名:---" );
//设置一个boolean类型的flg标志,若查找不到则为false
boolean flg = false ;
string name = sc.next();
for ( int i= 0 ; i<=len; i++) {
if (emp[i].getname().equals(name)) {
printemployee(emp[i]);
system.out.println( "---请按照提示输入修改信息---" );
system.out.print( "请输入员工编号:" );
emp[i].setid(sc.next());
system.out.print( "请输入员工姓名:" );
emp[i].setname(sc.next());
system.out.print( "请输入员工职务(员工、经理、懂事):" );
emp[i].setjob(sc.next());
system.out.print( "请输入员工请假天数:" );
emp[i].setholiday(sc.nextint());
system.out.print( "请输入员工基本工资:" );
emp[i].setsalary(sc.nextdouble());
//修改完成后打印一下
printemployee(emp[i]);
system.out.println( "修改成功!" );
flg = true ;
break ;
}
}
if (!flg) {
system.out.println( "查无此人,请重新输入:" );
updateemployee();
}
}
/**
* 根据姓名查找雇员信息
* @param args
*/
public void findemployee() {
system.out.println( "------查找员工------" );
system.out.println( "---请输入员工姓名:---" );
//设置一个boolean类型的flg标志,若查找不到则为false
boolean flg = false ;
string name = sc.next();
for ( int i= 0 ; i<=len; i++) {
if (emp[i].getname().equals(name)) {
printemployee(emp[i]);
system.out.println( "查找成功!" );
flg = true ;
break ;
}
}
if (!flg) {
system.out.println( "查无此人,请重新输入:" );
findemployee();
}
}
/**
* 打印雇员信息
* @param args
*/
public void printemployee(employee em) {
system.out.print( " 编号: " + em.getid());
system.out.print( " 姓名: " + em.getname());
system.out.print( " 职务: " + em.getjob());
system.out.print( " 请假天数 : " + em.getholiday());
//参数:1.基本工资 2.请假天数
double sum = em.sunsalary(em.getsalary(), em.getholiday());
system.out.println( " 工资:" + sum);
}
public static void main(string[] args) {
testemd te = new testemd();
//开始界面
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( "|----------------|" );
//业务选择
label : while ( true ) {
system.out.println( "请选择业务:" );
int select = sc.nextint();
switch (select) {
case 1 : //添加新雇员
te.addemployee();
break ;
case 2 : //删除雇员
te.deleteemployee();
break ;
case 3 : //修改雇员信息
te.updateemployee();
break ;
case 4 : //根据姓名查找雇员信息
te.findemployee();
break ;
case 0 : //退出
system.out.println( "退出成功!" );
break label;
default :
system.out.println( "您输入的数字不正确!" );
break ;
}
}
}
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。
原文链接:http://blog.csdn.net/liguangliang_bzu/article/details/48198339
相关文章
猜你喜欢
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-25 49
-
2025-05-25 31
-
详解Spring Cloud Stream使用延迟消息实现定时任务(RabbitMQ)
2025-05-29 43 -
使用自助建站微信小程序时,怎样选择合适的模板以匹配品牌形象?
2025-06-04 78 -
2025-05-29 88
热门评论