一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|JavaScript|易語言|

服務器之家 - 編程語言 - JAVA教程 - Java實現員工管理系統

Java實現員工管理系統

2021-03-18 12:04SleepException JAVA教程

這篇文章主要為大家詳細介紹了Java實現員工管理系統,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
//父類
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);
 }
}

三個子類:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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);
 }
}

接下來就是關鍵的測試類,這里完成增刪改查== 有點多。

?
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产首页精品 | 欧美国产日韩综合 | 全彩调教侵犯h本子全彩妖气he | 欧美大片一区 | 日本中文字幕不卡在线一区二区 | 俄罗斯三级完整版在线观看 | 99视频导航 | 国产欧美久久久精品影院 | 欧美一区二区三区四区五区六区 | 色老大在线 | 爆操| 色呦阁 | 99在线免费视频 | 极品主播的慰在线播放 | 亚洲成人伦理 | 日本中文字幕二区三区 | 久久精品中文字幕 | 特黄特a级特别特级特毛片 特黄a级三级三级野战 | 亚洲第五页 | 日韩资源| 精品国产国产综合精品 | caoporm碰最新免费公开视频 | 波多野结衣黑人系列在线观看 | 男人视频网站 | 欧美亚洲另类在线观看 | 非洲黑人xxxxxbbbbb | 婷婷久久热99在线精品 | 奇米视频7777| 精品国产福利一区二区在线 | 男女男在线精品网站免费观看 | 亚洲国产精品综合久久一线 | a4yy欧美一区二区三区 | 日本精品欧洲www | 欧美成人香蕉在线观看 | 男女爆操 | 亚洲国产高清视频 | 波多野结衣在线观看视频 | 扒开女人下面 | 好爽轻点太大了太深了 | 色依依视频视频在线观看 | 国产japanese孕妇孕交 |