Java實(shí)現(xiàn)員工管理系統(tǒng)
本文實(shí)例為大家分享了Java實(shí)現(xiàn)員工管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
本系統(tǒng)主要練習(xí)到的相關(guān)內(nèi)容:
1、 流程控制語(yǔ)句
2、 類(lèi)、對(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ì)思路:

員工父類(lèi)一個(gè),普通員工,經(jīng)理,董事長(zhǎng)子類(lèi)各一個(gè),分別重寫(xiě)父類(lèi)的工資方法。最后一個(gè)測(cè)試類(lèi)。
實(shí)現(xiàn)后界面如圖:

父類(lèi)子類(lèi)的編寫(xiě)沒(méi)什么問(wèn)題,注意盡量做好封裝,屬性最好用private修飾。小編偷了個(gè)懶,主要把時(shí)間用在測(cè)試類(lèi)的編寫(xiě)上o( ̄ε ̄*)o。
注意:由于本系統(tǒng)只是將對(duì)象存于對(duì)象數(shù)組,數(shù)組初始化時(shí)定長(zhǎng)設(shè)定為100,系統(tǒng)會(huì)自動(dòng)初始化每個(gè)數(shù)組元素為null,所以在寫(xiě)測(cè)試類(lèi)的方法時(shí)一定注意寫(xiě)好判斷預(yù)防遍歷賦值發(fā)生的空指針錯(cuò)誤,小編比較笨,所以饒了好一會(huì)才寫(xiě)出來(lái)(¬_¬)
還有就是如果更改員工的資料時(shí)注意,若是員工的職位發(fā)生變化該怎么處理,畢竟對(duì)象變了,處理工資的方法也不一樣。
以下貼出代碼:
首先是父類(lèi)Employee
//父類(lèi)
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è)子類(lèi):
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è)試類(lèi),這里完成增刪改查== 有點(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í)有所幫助,也希望大家多多支持腳本之家。
- Java精品項(xiàng)目瑞吉外賣(mài)之員工信息管理篇
- Java實(shí)現(xiàn)企業(yè)員工管理系統(tǒng)
- java實(shí)現(xiàn)員工工資管理系統(tǒng)
- Java實(shí)現(xiàn)員工信息管理系統(tǒng)
- Java實(shí)現(xiàn)簡(jiǎn)單員工管理系統(tǒng)
- Java實(shí)戰(zhàn)員工績(jī)效管理系統(tǒng)的實(shí)現(xiàn)流程
- Java 實(shí)戰(zhàn)范例之員工管理系統(tǒng)的實(shí)現(xiàn)
- 員工管理系統(tǒng)java版
- Java實(shí)現(xiàn)部門(mén)員工管理
相關(guān)文章
Java創(chuàng)建student類(lèi)詳細(xì)代碼例子
這篇文章主要給大家介紹了關(guān)于Java創(chuàng)建student類(lèi)的相關(guān)資料,學(xué)生類(lèi)(Student)是一種面向?qū)ο蟮木幊谈拍?其主要用于描述學(xué)生的屬性和行為,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-11-11
SpringBoot中fastjson自定義序列化和反序列化的實(shí)戰(zhàn)分享
在fastjson庫(kù)中,為了提供靈活的序列化和反序列化機(jī)制,設(shè)計(jì)了一系列的擴(kuò)展點(diǎn),以下是在SpringBoot和SpringClould環(huán)境中對(duì)這些擴(kuò)展點(diǎn)的詳細(xì)介紹及其實(shí)戰(zhàn)使用,通過(guò)代碼示例講解的非常詳細(xì),需要的朋友可以參考下2024-07-07
SpringCloud基本Rest微服務(wù)工程搭建過(guò)程
這篇文章主要介紹了SpringCloud基本Rest微服務(wù)工程搭建,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-01-01
Spring AOP注解失效的坑及JDK動(dòng)態(tài)代理
這篇文章主要介紹了Spring AOP注解失效的坑及JDK動(dòng)態(tài)代理,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03
Java中null的意義及其使用時(shí)的注意事項(xiàng)說(shuō)明
這篇文章主要介紹了Java中null的意義及其使用時(shí)的注意事項(xiàng)說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-09-09

