1、package exercise; import java.io.*; class staffInfo //职工类 { public String name; public String num; public String sex; public String age; public String record; public String position; public String wanges; public String tel; public String addr; } public class
2、StaffInfomation //实现部分 { public static void main(final String[] args) throws IOException { staffInfo staffOne[]=new staffInfo[100]; for(int j=0;j<100;j++) staffOne[j] = new staffInfo(); final ways staffTwo=new ways(); staffTwo.caidan(staffOne); staffTwo.creat(s
3、taffOne); staffTwo.output(staffOne); staffTwo.search(staffOne); staffTwo.delete(staffOne); } } class ways //方法类,主要实现职工信息的建立,显示,查找,删除,信息的保存与读取;这个类是整个程序的操作类。 { public String recordkey; public int i=0;//i用来存放职工的人数 public String filename="Infomation.txt"; Bu
4、fferedReader buf=new BufferedReader(new InputStreamReader(System.in)); void caidan(staffInfo staffOne[]) throws IOException { final BufferedReader buf=new BufferedReader(new InputStreamReader(System.in)); //此处是JAVA语言中输入数据的基本格式,功能有如C中的scanf函数 int choice; do{ System.out.printl
5、n("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓"); System.out.println("┃★ ★★ ★ ★★ ★ ★职工管理系统主菜单界面★ ★ ★★ ★ ★★ ★┃"); System.out.println("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫"); System.out.println("┃ ★ ★ ★ 1.输入职工信息 ★ ★ ★ ┃");
6、 System.out.println("┃ ★ ★ ★ 2.预览职工信息 ★ ★ ★ ┃"); System.out.println("┃ ★ ★ ★ 3.查找职工信息 ★ ★ ★ ┃"); System.out.println("┃
7、 ★ ★ ★ 4.删除职工信息 ★ ★ ★ ┃"); System.out.println("┃ ★ ★ ★ 5.读取已存数据 ★ ★ ★ ┃"); System.out.println("┃ ★ ★ ★ 6.安全退出系统 ★ ★ ★
8、 ┃"); System.out.println("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"); System.out.print(" 请输入您需要的功能代号(1--6):"); choice=Integer.parseInt(buf.readLine()); switch(choice){ case 1:creat(staffOne);break; case 2:output(staffOne);break;
9、 case 3:search(staffOne);break; case 4:delete(staffOne);break; case 5:read(staffOne);break; case 6:save(staffOne);break; } } while(choice!=0); } void creat(staffInfo staffOne[]) throws IOException { final BufferedReader buf=new BufferedReader(ne
10、w InputStreamReader(System.in)); System.out.print("请输入职工信息(以0结束)\n"); System.out.print("姓名:"); staffOne[i].name=buf.readLine(); //用数组staffOne[i]来暂存职工的相关信息 while(staffOne[i]pareTo("0")!=0) //用compareTo方法确定判定是否应该写入新信息 { System.out.print("工号:"); staffOne[i].num=buf.readLine();
11、 System.out.print("性别:"); staffOne[i].sex=buf.readLine(); System.out.print("年龄:"); staffOne[i].age=buf.readLine(); System.out.print("学历:"); staffOne[i].record=buf.readLine(); System.out.print("职位:"); staffOne[i].position=buf.readLine(); System.out.print("工资:"); staffOne[i].wange
12、s=buf.readLine(); System.out.print("电话:"); staffOne[i].tel=buf.readLine(); System.out.print("住址:"); staffOne[i].addr=buf.readLine(); i++; System.out.println("请输入下一个职工信息:"); staffOne[i].name=buf.readLine(); } } void output(staffInfo staffOne[]) throws IOException //这里是实现“输出(预览)职
13、工信息”output的模块 { for(int j=0;j
14、 "); System.out.println("-------------------------------------------------------------------------------------------------"); System.out.println("姓名\t工号\t\t性别\t年龄\t学历\t职位 \t\t工 资\t电话号码 \t\t住址"); System.out.println("---------------------------------------------------------
15、"); System.out.print(staffOne[j].name+"\t"+staffOne[j].num+"\t"+staffOne[j].sex+"\t"+staffOne[j].age+"\t"+staffOne[j].record+"\t"+staffOne[j].position+"\t\t"+staffOne[j].wanges+"\t"+staffOne[j].tel+"\t"+staffOne[j].addr+"\n"); System.out.println(
16、"-------------------------------------------------------------------------------------------------"); } else System.out.println("没有职工信息!"); } } void search(staffInfo staffOne[]) throws IOException { final BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
17、 System.out.print("请输入您要查找的职工工号:"); recordkey=buf.readLine(); boolean flg=true; for(int j=0;j
18、"); System.out.println(" *职工信息表* "); System.out.println("--------------------------------------------------------------------------------------"); System.out.println("姓名\t工号\t\t性别\t年龄\t学历\t职位 \t\t工 资\t电话号
19、码 \t\t住址"); System.out.println("--------------------------------------------------------------------------------------"); System.out.println(staffOne[j].name+"\t"+staffOne[j].num+"\t"+staffOne[j].sex+"\t"+staffOne[j].age+"\t"+staffOne[j].record+"\t"+staffOne[j].position+"\t\t"+staffOne[j
20、].wanges+"\t"+staffOne[j].tel+"\t"+staffOne[j].addr+"\n"); flg=false; } } if(flg) System.out.println("对不起,查无此人!"); } void delete(staffInfo staffOne[]) throws IOException { final BufferedReader buf=new BufferedReader(new InputStreamReader(System.in)); System.o
21、ut.print("请输入您要删除的职工工号:"); recordkey=buf.readLine(); boolean flg=true; for(int j=0;j
22、 staffOne[k].name=staffOne[k+1].name ; staffOne[k].num=staffOne[k+1].num ; staffOne[k].sex=staffOne[k+1].sex; staffOne[k].age=staffOne[k+1].age ; staffOne[k].record=staffOne[k+1].record ; staffOne[k].position=s
23、taffOne[k+1].position ; staffOne[k].wanges=staffOne[k+1].wanges ; staffOne[k].tel=staffOne[k+1].tel ; staffOne[k].addr=staffOne[k+1].addr ; } i--;//职工人数减一 flg=false; } } if(flg) System.out.println("对
24、不起,查无此人!。"); else System.out.println("已经删除该职工信息!。"); } void save(staffInfo staffOne[]) throws IOException //数据的保存模块,把输入的职工信息保存到相应的文件里。 { int k; final FileWriter fw=new FileWriter(filename);//调用构造函数FileWriter()创建FileWriter类的对象。 fw.write( i+"\n");//把职工的人数保存到文件中以便下次读取时使用 for( k=0;k<
25、i;k++)//每个职工有9个信息字段,下面就是这9个信息段。 { fw.write( staffOne[k].name+"\n"); fw.write( staffOne[k].num+"\n"); fw.write( staffOne[k].sex+"\n" ); fw.write( staffOne[k].age+"\n"); fw.write( staffOne[k].record+"\n"); fw.write( staffOne[k].position+"\n") ; fw.write( staffOne[k].wanges+"\n
26、"); fw.write( staffOne[k].tel+"\n"); fw.write( staffOne[k].addr+"\n"); } fw.close(); System.out.println("系统已经安全退出!感谢您的使用!"); System.exit(0); } void read(staffInfo staffOne[]) throws IOException { final FileReader fr=new FileReader(filename); final BufferedReader bfr=
27、new BufferedReader(fr); if((recordkey=bfr.readLine())!=null) i=Integer.parseInt(recordkey); for(int j=0;j






