用Java写一个公司员工管理系统!
用Java写一个公司员工管理系统!
今天看CSDN发现写管理系统的文章不少,我在这里也给大家用java写一篇!(当然这里只是最简单的那种qwq)
核心功能:对员工各项信息的管理
采用属性文件+资源文件(支持中文简体和英文)
目录
- 第一步:创建一个记录员工信息的文件
- 第二步:循环处理输入的信息
- 第三步:用类及框架来完成对员工内容的管理
事不宜迟,现在就开始吧!
先创建一个Member类
package 管理;
public class Member {
private String name;
private String money;
private String post;
public Member(String name,String money,String post) {
this.name = name;
this.money = money;
this.post = post;
}
@Override
public boolean equals(Object obj) { //完成员工删除和查询的必要方法
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof Member)) {
return false;
}
Member mem = (Member) obj;
return this.name.equals(mem.name) && this.money.equals(mem.money) && this.post.equals(mem.post);
}
public String toString() { //输出员工信息的方法
return this.name + ":" + this.money + ":" + this.post + "|";
}
}
为了使程序更加流畅,再加一个垃圾处理的线程Optimization
package 管理;
public class Optimization extends Thread {
private String title;
private int number;
private int wait;
public Optimization(String title,int number,int wait) {
this.title = title;
this.number = number;
this.wait = wait;
}
@Override
public void run() {
Runtime runtime =Runtime.getRuntime();
System.out.println("[IO]name:" + this.title + ",member:" + this.number);
while (true) {
runtime.gc();
try {
Thread.currentThread().sleep(this.wait);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
最后创建主类 ManagementSystem
package 管理;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Scanner;
public class ManagementSystem {
public static void main(String args[]) throws Exception{
ResourceBundle resource = ResourceBundle.getBundle("管理.config");
System.out.println(resource.getString("info.1"));
new Optimization("Optimization",10,10000).start();
System.out.println(resource.getString("info.2"));
List<Member> all = new ArrayList<Member>();
System.out.println(resource.getString("info.3"));
File file = new File("./managementsystem");
File read = new File("./managementsystem/info.txt");
System.out.println(resource.getString("info.4"));
if (file.exists()) {
if (read.exists()) {
try {
System.out.println(resource.getString("info.5"));
InputStream input = new FileInputStream(read);
byte data [] = input.readAllBytes();
String str = new String(data);
String result[] =str.split("\\|");
for (int x = 0; x < result.length; x ++) {
String temp[] = result[x].split(":");
all.add(new Member(temp[0], temp[1], temp[2]));
}
} catch(Exception e) {
if (read.exists()) {
read.delete();
}
System.out.println(resource.getString("info.6"));
System.exit(1);
}
System.out.println(resource.getString("info.7"));
} else {
System.out.println(resource.getString("info.8"));
read.createNewFile();
System.out.println(resource.getString("info.9"));
all.add(new Member("try" , "0", "try"));
}
} else {
file.mkdir();
System.out.println(resource.getString("info.8"));
read.createNewFile();
System.out.println(resource.getString("info.9"));
all.add(new Member("try" , "0", "try"));
}
PrintWriter pu = new PrintWriter(new FileOutputStream(read));
System.out.println(resource.getString("info.10"));
System.out.println(resource.getString("info.11"));
while (true) {
System.out.println(resource.getString("info.12"));
Scanner scanner = new Scanner(System.in);
int i = scanner.nextInt();
int n = 0;
try {
switch (i) {
case 0:
System.out.print(resource.getString("info.13"));
break;
case 1:
System.out.print(resource.getString("info.14"));
Scanner scanner1 = new Scanner(System.in);
String name = scanner.next();
System.out.print(resource.getString("info.25"));
Scanner scanner2 = new Scanner(System.in);
String member = scanner.next();
System.out.print(resource.getString("info.26"));
Scanner scanner3 = new Scanner(System.in);
String card = scanner.next();
all.add(new Member(name, member, card));
System.out.println(resource.getString("info.27"));
break;
case 2:
System.out.print(resource.getString("info.15"));
Scanner scanner11 = new Scanner(System.in);
String name1 = scanner.next();
System.out.print(resource.getString("info.25"));
Scanner scanner12 = new Scanner(System.in);
String member1 = scanner.next();
System.out.print(resource.getString("info.26"));
Scanner scanner13 = new Scanner(System.in);
String card1 = scanner.next();
all.remove(new Member(name1, member1, card1));
System.out.println(resource.getString("info.28"));
break;
case 3:
System.out.print(resource.getString("info.16"));
all.forEach(System.out::println);
System.out.print(resource.getString("info.17"));
break;
case 4:
System.out.print(resource.getString("info.18"));
Scanner scanner21 = new Scanner(System.in);
String name2 = scanner.next();
System.out.print(resource.getString("info.25"));
Scanner scanner22 = new Scanner(System.in);
String member2 = scanner.next();
System.out.print(resource.getString("info.26"));
Scanner scanner23 = new Scanner(System.in);
String card2 = scanner.next();
if (all.contains(new Member(name2, member2, card2))) {
System.out.println(resource.getString("info.19"));
} else {
System.out.println(resource.getString("info.20"));
}
break;
case 5:
System.out.println("=====ManagementSystem=====");
System.out.println("=====author: Yaoboyu======");
System.out.println("===version: beta1.00.1====");
System.out.println("=====language: zh_CN======");
System.out.println("==Thanks for using this!==");
break;
case 6:
System.out.println(resource.getString("info.22"));
all.forEach(pu::print);
pu.close();
System.out.println(resource.getString("info.23"));
System.out.println(resource.getString("info.24"));
System.exit(i);
}
} catch(Exception e) {
break;
}
}
}
}
资源文件[这里就只放中文的哈!]:
info.1=[System]初始化中…
info.2=[System]优化线程启动成功!
info.3=[System]类及框架模块启动成功!
info.4=[System]IO读取流模块启动成功!
info.5=[IO]读取文件中…
info.6=检测到一个错误![建议:删除配置文件重新启动]
info.7=[IO]读取完成!
info.8=[IO]检测到未创建存档,正在创建存档!
info.9=[IO]创建成功![请勿随意更改配置文件!否则后果自负!]
info.10=[System]IO打印流模块启动成功!\n[System]初始化完成!
info.11=欢迎来到员工管理系统
info.12=请输入指令[输入0查询指令]
info.13=\n帮助\n1-添加员工\n2-删除员工\n3-获取全部员工信息\n4-查询员工是否存在\n5-获取程序信息\n6-退出程序\n================\n
info.14=添加员工\n请输入名称:
info.15=删除员工\n请输入名称:
info.16=输出所有数据\n员工名:员工工资:员工职务
info.17=完毕\n\n
info.18=查询员工\n请输入名称:
info.19=此员工存在!
info.20=此员工不存在!
info.21=请输入目标地址:
info.22=保存中…
info.23=关闭中…
info.24=关闭成功!
info.25=请输入工资:
info.26=请输入职位:
info.27=创建成功!
info.28=完成!
资源文件也都在下面的整合文件中
站内下载地址:点我!
源码下载地址(站外):别点他,点我!
新人作者,多多支持哈!
原文地址: https://blog.csdn.net/qq_56323695/article/details/118861482
本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
相关文章