本文實(shí)例為大家分享了Java實(shí)現(xiàn)員工管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
專注于為中小企業(yè)提供成都網(wǎng)站制作、做網(wǎng)站服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)皮山免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了1000+企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
本系統(tǒng)主要練習(xí)到的相關(guān)內(nèi)容:
1、 流程控制語(yǔ)句
2、 類、對(duì)象
3、 封裝、繼承、多態(tài)
4、 方法的重載、重寫(xiě)
5、 訪問(wèn)修飾符
6、 static
需求說(shuō)明:
員工信息的基本情況
—————————普通員工—————————–
屬性:?jiǎn)T工編號(hào)、員工姓名、員工職務(wù)、請(qǐng)假天數(shù)、基本工資
普通員工工資:
在基本工資的基礎(chǔ)上增加10%的工作餐,50%的崗位補(bǔ)助,200元住房補(bǔ)助
基本工資+基本工資*0.1+基本工資*0.5+200
—————————–經(jīng)理——————————–
屬性:?jiǎn)T工編號(hào)、員工姓名、員工職務(wù)、請(qǐng)假天數(shù)、基本工資
經(jīng)理工資:
在基本工資的基礎(chǔ)上增加20%的工作餐,50%的崗位補(bǔ)助,500元住房補(bǔ)助
基本工資+基本工資*0.2+基本工資*0.5+500
——————————-董事——————————–
屬性:?jiǎn)T工編號(hào)、員工姓名、員工職務(wù)、請(qǐng)假天數(shù)、基本工資
董事工資:
在基本工資的基礎(chǔ)上增加8%的工作餐,30%的崗位補(bǔ)助,2000元住房補(bǔ)助,3000元投資補(bǔ)助
基本工資+基本工資*0.08+基本工資*0.3+2000+3000
——————————–其他———————————
工資扣除部分,所有員工都一樣
無(wú)請(qǐng)假,基本工資全發(fā),有請(qǐng)假,扣除每天平均工資 * 請(qǐng)假天數(shù)
大體設(shè)計(jì)思路:
員工父類一個(gè),普通員工,經(jīng)理,董事長(zhǎng)子類各一個(gè),分別重寫(xiě)父類的工資方法。最后一個(gè)測(cè)試類。
實(shí)現(xiàn)后界面如圖:
父類子類的編寫(xiě)沒(méi)什么問(wèn)題,注意盡量做好封裝,屬性最好用private修飾。小編偷了個(gè)懶,主要把時(shí)間用在測(cè)試類的編寫(xiě)上o( ̄ε ̄*)o。
注意:由于本系統(tǒng)只是將對(duì)象存于對(duì)象數(shù)組,數(shù)組初始化時(shí)定長(zhǎng)設(shè)定為100,系統(tǒng)會(huì)自動(dòng)初始化每個(gè)數(shù)組元素為null,所以在寫(xiě)測(cè)試類的方法時(shí)一定注意寫(xiě)好判斷預(yù)防遍歷賦值發(fā)生的空指針錯(cuò)誤,小編比較笨,所以饒了好一會(huì)才寫(xiě)出來(lái)(¬_¬)
還有就是如果更改員工的資料時(shí)注意,若是員工的職位發(fā)生變化該怎么處理,畢竟對(duì)象變了,處理工資的方法也不一樣。
以下貼出代碼:
首先是父類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+",請(qǐng)假天數(shù):"+holiday+",工資:"+salary); } }
三個(gè)子類:
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); } }
接下來(lái)就是關(guān)鍵的測(cè)試類,這里完成增刪改查== 有點(diǎn)多。
public class TestEMD { static Scanner sc = new Scanner(System.in); static Employee[] em = new Employee[100]; public static void caoZuo() { System.out.println("---- 工資管理系統(tǒng) ----"); 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("請(qǐng)輸入你要選擇的操作:"); 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("指令錯(cuò)誤請(qǐng)重新輸入!"); caoZuo(); break; } } public static void addEmployee() { System.out.println("------增加員工------"); System.out.println("請(qǐng)輸入相關(guān)信息:"); System.out.print("ID:"); String id = sc.next(); System.out.print("姓名:"); String name = sc.next(); System.out.print("職務(wù):"); String position = sc.next(); System.out.print("請(qǐng)假天數(shù):"); 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 "經(jīng)理": Employee b = new Manager(); b.ID = id; b.name = name; b.position = "經(jīng)理"; 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 "董事長(zhǎng)": Employee c = new Director(); c.ID = id; c.name = name; c.position = "董事長(zhǎng)"; 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("不存在此職務(wù),請(qǐng)重新輸入!"); addEmployee(); break; } caoZuo(); } public static void delEmployee() { System.out.println("----------刪除員工---------"); System.out.println("請(qǐng)輸入員工姓名:"); String n = sc.next(); for (int i = 0; i < 100; i++) { if (em[i] != null) { if (em[i].name.equals(n)) { System.out.println("你要?jiǎng)h除的是:" + em[i].toString()); System.out.println("你確定要?jiǎng)h除嗎?\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("輸入指令不正確,請(qǐng)重新輸入!"); delEmployee(); } } else { if (i != 99) { continue; } else { System.out.println("你輸入的賬號(hào)不存在!請(qǐng)重新輸入!"); delEmployee(); } } } else { if (i != 99) { continue; } else { System.out.println("你輸入的賬號(hào)不存在!請(qǐng)重新輸入!"); delEmployee(); } } } } public static void updateEmployee() { System.out.println("--------------修改員工資料-------------"); System.out.println("請(qǐng)輸入你要修改的姓名:"); 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("請(qǐng)重新輸入相關(guān)信息:"); System.out.print("ID:"); String id = sc.next(); System.out.print("姓名:"); String name = sc.next(); System.out.print("職務(wù):"); String position = sc.next(); System.out.print("請(qǐng)假天數(shù):"); 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 "經(jīng)理": if (em[i].position.equals("經(jīng)理")) { 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 = "經(jīng)理"; 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 "董事長(zhǎng)": if (em[i].position.equals("董事長(zhǎng)")) { 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 = "董事長(zhǎng)"; 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("不存在此職務(wù),請(qǐng)重新輸入!"); 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("你輸入的員工不存在!請(qǐng)重新輸入!"); caoZuo(); } } } else { if (i != 99) { continue out; } else { System.out.println("你輸入的員工不存在!請(qǐng)重新輸入!"); 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(); } }
程序剛寫(xiě)完就來(lái)發(fā)帖了,簡(jiǎn)單測(cè)試并未發(fā)現(xiàn)什么問(wèn)題,若是大家發(fā)現(xiàn)有什么不對(duì)的歡迎指正,謝謝啦。
更多學(xué)習(xí)資料請(qǐng)關(guān)注專題《管理系統(tǒng)開(kāi)發(fā)》。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。