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 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(staffOne);staffTwo.output(staffOne);staffTwo.search(staffOne);staffTwo.delete(staffOne);}}class ways //方法类,主要实现职工信息的建立,显示,查找,删除,信息的保存与读取;这个类是整个程序的操作类。
{public String recordkey;public int i=0;//i用来存放职工的人数public String filename="Infomation.txt";BufferedReader 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.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){case 1:creat(staffOne);break;case 2:output(staffOne);break;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(new 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();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();}}void output(staffInfo staffOne[]) throws IOException //这里是实现“输出(预览)职工信息”output的模块{for(int j=0;j<i;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("-------------------------------------------------------------------------------------------------");}else System.out.println("没有职工信息!");}}void search(staffInfo staffOne[]) throws IOException{final BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));System.out.print("请输入您要查找的职工工号:");recordkey=buf.readLine();boolean flg=true;for(int j=0;j<i;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("对不起,查无此人!");}void delete(staffInfo staffOne[]) throws IOException{final BufferedReader buf=new BufferedReader(new InputStreamReader(System.in)); System.out.print("请输入您要删除的职工工号:");recordkey=buf.readLine();boolean flg=true;for(int j=0;j<i;j++){System.out.println("输入的工号为:"+recordkey);if(recordkey.equals(staffOne[j].num)){for(int k=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=false;}}if(flg)System.out.println("对不起,查无此人!。