packageexercise;importjava.io.*;classstaffInfo//职工类{publicStringname;publicStringnum;publicStringsex;publicStringage;publicStringrecord;publicStringposition;publicStringwanges;publicStringtel;publicStringaddr;}publicclassStaffInfomation//实现部分{publicstaticvoidmain(finalString[]args)throwsIOException{staffInfostaffOne[]=newstaffInfo[100];for(intj=0;j100;j++)staffOne[j]=newstaffInfo();finalwaysstaffTwo=newways();staffTwo.caidan(staffOne);staffTwo.creat(staffOne);staffTwo.output(staffOne);staffTwo.search(staffOne);staffTwo.delete(staffOne);}}classways//方法类,主要实现职工信息的建立,显示,查找,删除,信息的保存与读取;这个类是整个程序的操作类。{publicStringrecordkey;publicinti=0;//i用来存放职工的人数publicStringfilename=Infomation.txt;BufferedReaderbuf=newBufferedReader(newInputStreamReader(System.in));voidcaidan(staffInfostaffOne[])throwsIOException{finalBufferedReaderbuf=newBufferedReader(newInputStreamReader(System.in));//此处是JAVA语言中输入数据的基本格式,功能有如C中的scanf函数intchoice;do{System.out.println(┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓);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(┃★★★5.读取已存数据★★★┃);System.out.println(┃★★★6.安全退出系统★★★┃);System.out.println(┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛);System.out.print(请输入您需要的功能代号(1--6):);choice=Integer.parseInt(buf.readLine());switch(choice){case1:creat(staffOne);break;case2:output(staffOne);break;case3:search(staffOne);break;case4:delete(staffOne);break;case5:read(staffOne);break;case6:save(staffOne);break;}}while(choice!=0);}voidcreat(staffInfostaffOne[])throwsIOException{finalBufferedReaderbuf=newBufferedReader(newInputStreamReader(System.in));System.out.print(请输入职工信息(以0结束)\n);System.out.print(姓名:);staffOne[i].name=buf.readLine();//用数组staffOne[i]来暂存职工的相关信息while(staffOne[i].name.compareTo(0)!=0)//用compareTo方法确定判定是否应该写入新信息{System.out.print(工号:);staffOne[i].num=buf.readLine();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].wanges=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();}}voidoutput(staffInfostaffOne[])throwsIOException//这里是实现“输出(预览)职工信息”output的模块{for(intj=0;ji;j++){if(i!=0){System.out.println(------------------------------------------------------------------------------------------------);System.out.println(*职工信息表*);System.out.println(-------------------------------------------------------------------------------------------------);System.out.println(姓名\t工号\t\t性别\t年龄\t学历\t职位\t\t工资\t电话号码\t\t住址);System.out.println(-------------------------------------------------------------------------------------------------);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(-------------------------------------------------------------------------------------------------);}elseSystem.out.println(没有职工信息!);}}voidsearch(staffInfostaffOne[])throwsIOException{finalBufferedReaderbuf=newBufferedReader(newInputStreamReader(System.in));System.out.print(请输入您要查找的职工工号:);recordkey=buf.readLine();booleanflg=true;for(intj=0;ji;j++){if(recordkey.equals(staffOne[j].num))//equals是字符串比较函数相等返回true{System.out.println(-------------------------------------------------------------------------------------);System.out.println(*职工信息表*);System.out.println(--------------------------------------------------------------------------------------);System.out.println(姓名\t工号\t\t性别\t年龄\t学历\t职位\t\t工资\t电话号码\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].wanges+\t+staffOne[j].tel+\t+staffOne[j].addr+\n);flg=false;}}if(flg)System.out.println(对不起,查无此人!);}voiddelete(staffInfostaffOne[])throwsIOException{finalBufferedReaderbuf=newBufferedReader(newInputStreamReader(System.in));System.out.print(请输入您要删除的职工工号:);recordkey=buf.readLine();booleanflg=true;for(intj=0;ji;j++){System.out.println(输入的工号为:+recordkey);if(recordkey.equals(staffOne[j].num)){for(intk=j;k=i-1;k++)//利用顺序表的删除算法,删除值之后,再把后面的值往前移位,从而实现删除{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=staffOne[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=fa