员工信息管理系统java_第1页
员工信息管理系统java_第2页
员工信息管理系统java_第3页
员工信息管理系统java_第4页
员工信息管理系统java_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、员工信息管理系统java云南大学x年春季学期信息学院 电子信息工程x级 面向对象信息系统开发期末检测(堂下测试)试卷a 满分100分 考试时间:150分钟 任课教师:高莲 学院:信息学院 专业:电子信息工程 学号:x1060261 姓名:李康,周五班,33号 题号 1 2 3 4 总分 得分 x年春季学期面向对象信息系统开发期末检测题 一、编写一个java应用程序,对员工信息进行管理,功能实现详述如下: 1. 请先通过java代码创建文件employ以表格形式存储雇员的相关信息。雇员类的相关属性说明如下:列名 数据类型 employ_id int (该列为员工编号,不能重复) employ_n

2、ame varchar employ_address varchar employ_salary float employ_phone varchar employ_department varchar (市场部、财务部、人事部、研发部、生产车间)2. 通过java代码向employ文件中写入初始数据:1 王五 山东 4500管理部 2 安心 贵州 1200生产车间 3 杨燕 四川 6300研发部 3、创建菜单选项 1、添加记录 2、修改记录 3、删除记录 4、搜索记录 5、退出 4、选定相关菜单后,提示用户进行相关

3、操作 1)、添加记录 提示用户输入相关数据,并检测输入数据的有效性及是否与文件中数据重复,并将操作数据结果显示给用户进行查看;2)、修改记录 提示用户输入要修改记录员工的employ_id,查找该用户是否存在,不存在提醒用户该雇员信息不存在;存在的话,提示用户输入新的employ_salary(其它数据列暂时不允许修改);3)、删除记录 提示用户输入要删除记录员工的employ_id,查找该用户是否存在,不存在提醒用户该雇员信息不存在;存在的话,将该行数据删除;4)、搜索记录 提示用户输入要删除记录员工的employ_name,若雇员存在,将搜索信息显示出来;若该雇员不存在,在提示无此雇员存在

4、; 5)、退出 运行system.exit(0);退出程序。数据的有效性说明如下:a、 employ_name只能是字符,最多不超过10个;b、 employ_salary为员工工资,应该大于当地最低工资(800);c、 employ_phone为员工电话号码,应该都为数字,总长度为11;d、 employ_department取值为市场部、财务部、人事部、研发部、生产车间中一个。 一、实现思路: 二、源代码: public class abnormal public static boolean panduanid(string id)/判断id是否有效的方法 boolean flag=tr

5、ue; fileoperation temp=new fileoperation(“d:2.txt“); stringbuffer buffer1=temp.readfile; int result1=buffer1.indexof(id+“ “,0);/判断员工是否存在但不能确定是员工号还是手机号或薪水if(result11)/判断获得的位置,如果不是1,则加强判断条件 result1=buffer1.indexof(“:“+id+“ “,0); if(result1=-1)/不存在重复 flag=false; return flag; public static boolean pandu

6、anname(string name)/判断姓名是否有效的方法 string name1=name; boolean flag=false; pattern p=ppile(“.*d+.*“); matcher m=p.matcher(name1); if(m.matches) flag=true; return flag; public static boolean panduandepartment(string department)/判断部门是否有效的方法 boolean flag=false; if(department.equals(“市场部“)|“人事部“.e

7、quals(department)|“研发部“.equals(department)|“生产车间“.equals(department)|“财务部“.equals(department) flag=true; return flag; public class employdo extends javax.swing.jframe string newid; public employdo initcomponents; private void addcancelactionperformed(java.awt.event.actionevent evt) tianjiatankuang.s

8、etvisible(false); id.settext(“);/输入框摸空 name.settext(“); place.settext(“); money.settext(“); phonenum.settext(“); department.settext(“); private void addsureactionperformed(java.awt.event.actionevent evt) while(true)/异常处理区域 tryif(abnormal.panduanid(id.gettext) throw new exception; break; catch(except

9、ion ex) id.settext(joptionpane.showinputdialog(null, “错误!该员工已存在:n“,null); while(true)/异常处理区域 tryif(abnormal.panduanname(name.gettext) throw new exception; break; catch(exception ex) name.settext(joptionpane.showinputdialog(null, “错误!姓名中不可含有数字:n“,null); while(true) tryif(double.parsedouble(money.gett

10、ext)800) throw new exception; break; catch(exception ex) money.settext(joptionpane.showinputdialog(null, “错误!工资应高于或等于800元:n“,null); while(true) try boolean result2=phonenum.gettext.matches(“0-9+“); if(phonenum.gettext.length!=11|result2=false) throw new exception; break; catch(exception ex) phonenum

11、.settext(joptionpane.showinputdialog(null, “错误!请输入有效的手机号:n“,null); while(true) try if(abnormal.panduandepartment(department.gettext)=false) throw new exception; break; catch(exception ex) department.settext(joptionpane.showinputdialog(null, “错误!不存在该部门:n“,null); tianjiabingxianshi; public void tianji

12、abingxianshi/存入文件并重新显示 fileoperation temp=new fileoperation(“d:2.txt“); temp.writefile(id.gettext+“ “+name.gettext+“ “+place.gettext+“ “+money.gettext+“ “+phonenum.gettext+“ “+department.gettext); id.settext(“);/输入框摸空 name.settext(“); place.settext(“); money.settext(“); phonenum.settext(“); departme

13、nt.settext(“); tianjiatankuang.setvisible(false); joptionpane.showmessagedialog(null, “添加成功“, “提示“, joptionpane.plain_message); look.xianshi(this.biaoge1.getmodel,this.biaoge1.getrowcount); private void searchsureactionperformed(java.awt.event.actionevent evt) fileoperation temp=new fileoperation(“d

14、:2.txt“); stringbuffer buffer1=temp.readfile; int result1=buffer1.indexof(searchname.gettext+“ “,0);/判断员工是否存在 if(result1!=-1) searchtankuang.setvisible(false); function.search(buffer1,searchname.gettext+“ “ , this.biaoge2.getrowcount, this.biaoge2.getmodel); employinformationtankuang.setvisible(true

15、); else joptionpane.showmessagedialog(null, “没有找到此员工“, “抱歉“, joptionpane.warning_message); searchname.settext(“); private void searchcancelactionperformed(java.awt.event.actionevent evt) searchtankuang.setvisible(false); searchname.settext(“); private void deletesureactionperformed(java.awt.event.ac

16、tionevent evt) fileoperation temp=new fileoperation(“d:2.txt“); stringbuffer buffer1=temp.readfile; int result1=buffer1.indexof(deleteid.gettext+“ “,0);/如果不是第一个位置,则可能将其他数据当作员工id if(result1!=-1) function.delete(deleteid.gettext, buffer1); deleteid.settext(“); deletetankuang.setvisible(false); joption

17、pane.showmessagedialog(null, “删除成功“, “提示“, joptionpane.plain_message); look.xianshi(this.biaoge1.getmodel,this.biaoge1.getrowcount); else joptionpane.showmessagedialog(null, “没有找到此员工“, “抱歉“, joptionpane.warning_message); deleteid.settext(“); private void changesureactionperformed(java.awt.event.acti

18、onevent evt) newid=changeid.gettext; fileoperation temp=new fileoperation(“d:2.txt“); stringbuffer buffer1=temp.readfile; int result1=buffer1.indexof(changeid.gettext+“ “,0);/如果不是第一个位置,则可能将其他数据当作员工id if(result1=1)/不是第一个位置 result1=buffer1.indexof(“:“+changeid.gettext+“ “,0);/加强判断条件 if(result1!=-1) ch

19、angemoneytankuang.setvisible(true); else joptionpane.showmessagedialog(null, “没有找到此员工“, “抱歉“, joptionpane.warning_message); changeid.settext(“); private void changemoneysureactionperformed(java.awt.event.actionevent evt) while(true) tryif(double.parsedouble(changemoney.gettext)800) throw new excepti

20、on; break; catch(exception ex) changemoney.settext(joptionpane.showinputdialog(null, “错误!工资应高于或等于800元:n“,null); function.changemoney(changeid.gettext, changemoney.gettext); changeid.settext(“); changemoney.settext(“); changetankuang.setvisible(false); changemoneytankuang.setvisible(false); joptionpa

21、ne.showmessagedialog(null, “修改成功“, “提示“, joptionpane.plain_message); look.xianshi(this.biaoge1.getmodel,this.biaoge1.getrowcount); private void 警告sureactionperformed(java.awt.event.actionevent evt) fileoperation.deletefile(“d:2.txt“);/删除原文件信息 getit.deposit;/存入系统设定好的信息 system.out.println(“已成功初始化数据“);

22、 joptionpane.showmessagedialog(null, “已成功初始化数据“, “恭喜“, joptionpane.plain_message); look.xianshi(this.biaoge1.getmodel,this.biaoge1.getrowcount); jinggao.setvisible(false); public class fileoperation private string filepath; private file file; public void setfilepath(string filepath) this.filepath=fi

23、lepath; public string getfilepath return this.filepath; fileoperation fileoperation(string filepath) this.filepath=filepath; this.file=new file(this.filepath); if(!this.file.exists) try this.file.createnewfile; catch(ioexception ce) ce.printstacktrace; public stringbuffer readfile stringbuffer buffe

24、r=new stringbuffer; try string line=br.readline; while(line!=null) system.out.println(line); buffer.append(line+“:“); line=br.readline; br.close; fr.close; catch(ioexception ce) ce.printstacktrace; return buffer; public boolean writefile(string str) boolean success=true; try bufferedwriter bw=new bu

25、fferedwriter(fw); bw.write(str); bw.newline; bw.flush; fw.close; catch(ioexception ce) ce.printstacktrace; success=false; return success; return success; public static void deletefile(string filename) file file1=new file(filename); if(file1.isfilefile1.exists) file1.delete; system.out.println(“已经为您删

26、除“+filename+“处的文件“); else system.out.println(filename+“处无文件,将自动为您添加“); public class function public static void search(stringbuffer buffer1,string character,int infor1,tablemodel infor2) /找到员工信息并显示int result1=buffer1.indexof(character,0); defaulttablemodel tablemodel2=(defaulttablemodel)infor2; for(

27、int k=0;kinfor1;k+) tablemodel2.removerow(0); string child=new string6; int firstspace,secondspace,thirdspace,forthspace,fifthspace; firstspace=buffer1.indexof(“ “,result1); secondspace=buffer1.indexof(“ “,firstspace+1); thirdspace=buffer1.indexof(“ “,secondspace+1); forthspace=buffer1.indexof(“ “,t

28、hirdspace+1); fifthspace=buffer1.indexof(“:“,forthspace+1); child0=buffer1.substring(result1-3,result1-1); child1=buffer1.substring(result1,firstspace); child2=buffer1.substring(firstspace+1,secondspace); child3=buffer1.substring(secondspace+1,thirdspace); child4=buffer1.substring(thirdspace+1,forth

29、space); child5=buffer1.substring(forthspace+1,fifthspace); tablemodel2.addrow(child); public static void delete(string id,stringbuffer buffer1)/根据获得的位置进行删除 int result1=buffer1.indexof(id+“ “,0); if(result1=1)/不是第一个位置 result1=buffer1.indexof(“:“+id+“ “,0);/加强判断条件 string letter2,letter3; int duan=buff

30、er1.indexof(“ “,result1);/将位置后移避免永远都搜到自身 int newduan=buffer1.indexof(“:“,duan);/获得“:”的位置 if(0!=result1)/不是第一个位置的数 letter2=buffer1.substring(0,result1); letter3=buffer1.substring(newduan,buffer1.length-1); else letter2=buffer1.substring(0,result1); letter3=buffer1.substring(newduan+1,buffer1.length-1

31、); fileoperation temp5=new fileoperation(“d:2.txt“);/实例化一个对象 fileoperation.deletefile(“d:2.txt“);/删除原数据 temp5.writefile(letter2+letter3); public static void changemoney(string id,string money) fileoperation temp=new fileoperation(“d:2.txt“);/在文件里修改,思路:薪水前+新的薪水+薪水后 stringbuffer buffer1=temp.readfile;

32、/将文件读出来 int result1=buffer1.indexof(id,0);/判断文件字符串中是否有显示框中的内容并获得位置下标 string letter4,letter5; int firstspace,secondspace,thirdspace,forthspace; firstspace=buffer1.indexof(“ “,result1);/获得空格的位置 secondspace=buffer1.indexof(“ “,firstspace+1); thirdspace=buffer1.indexof(“ “,secondspace+1); forthspace=buf

33、fer1.indexof(“ “,thirdspace+1); letter4=buffer1.substring(0,thirdspace); letter5=buffer1.substring(forthspace+1,buffer1.length-1); fileoperation.deletefile(“d:2.txt“);/删除原数据 fileoperation temp5=new fileoperation(“d:2.txt“);/实例化一个对象 temp5.writefile(letter4+“ “+money+“ “+letter5); public class getit p

34、ublic static void deposit string firstformation=“01 王五 山东 4500管理部“; string secondformation=“02 安心 贵州 1200生产车间“; string thirdformation=“03 杨燕 四川 6300研发部“; fileoperation temp=new fileoperation(“d:2.txt“);/实例化一个对象 temp.writefile(firstformation+“n“+secondformation+

35、“n“+thirdformation); public class look public static void xianshi(tablemodel infor1,int infor2) fileoperation temp=new fileoperation(“d:2.txt“); stringbuffer buffer=temp.readfile;/将文件读出来 int count=0,start=0,end1,k=0;/count计算行数 while(true) end1=buffer.indexof(“:“,start);/获得第一个冒号的位置 count+; if(end1=buffer.length-1)/到达末尾 break; start=end1+1; string str=new stringcount;/创建用于存放每一段字符串的数组 start=0; defaulttablemodel tablemodel1=(defaulttablemodel)infor1; while(true) end1=buffer.indexof(“:“,start); strk=buffer.substring(start

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论