1、. .完整代码:1. 客户类class person:package客户管理系统;publicclass Person privateintnum;private String name;private String address;private String sex;public Person()public Person(intnum,String name,String address,String sex)this.num=num;this.name=name;this.address=address;this.sex=sex;publicvoid setNum(intnum)thi
2、s.num=num;publicint getNum()returnnum;publicvoid setName(String name)this.name=name;public String getName()returnname;publicvoid setAddress(String address)this.address=address;public String getAddress()returnaddress;publicvoid setSex(String sex)this.sex=sex;public String getSex()returnsex;public Str
3、ing toString() returnt+num+t+name+t+address+t+sex;2. 菜单类(class Menu):package客户管理系统;import java.util.Scanner;publicclass Menu Scanner input=new Scanner(System.in);public Menu() publicint showMenu() System.out.println(*);System.out.println(客户管理系统);System.out.println(=);System.out.println(【1】增加);System
4、.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(请选择操作:);returninput.nextInt();publicint subMenu() System.out.println(t【查询客户】);System.out.println(t1按客户编号查询);System.out.println(t2按客户XX查询)
5、;System.out.println(t3按地址查询);System.out.println(t4退出);System.out.println(t请选择查询编号);returninput.nextInt();3. 实际操作类class FileOperate :package客户管理系统;import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.io
6、.PrintWriter;import java.util.ArrayList;import java.util.List;import java.util.Scanner;publicclass FileOperate privatestatic String INFO=D:/info.dat;File file = new File(INFO);Scanner input=new Scanner(System.in);public FileOperate() if (!file.exists() try file.createNewFile();catch(IOException e) e
7、.printStackTrace();public List getList() throws NumberFormatException,IOExceptionBufferedReader br=new BufferedReader(new FileReader(file);String msg=null;List list =new ArrayList();while (msg =br.readLine()!=null) String arr=msg.split(t);intnum=Integer.parseInt(arr0);String name =arr1;String addres
8、s=arr2;String sex=arr3;Person person =new Person(num,name,address,sex);list.add(person);br.close();returnlist;privatevoid savelist(List list)throws FileNotFoundExceptionPrintWriter pw=new PrintWriter(new File(INFO);for (Person c:list) pw.format(%dt %st %st %st rn,c.getNum(),c.getName(),c.getAddress(
9、),c.getSex();pw.close();publicint getper(intnum) throws NumberFormatException,IOException List list=getList();for (inti=0;ilist.size();i+) Person per=list.get(i);if(num=per.getNum() returni; return -1; /增加publicvoid insert() throws NumberFormatException,IOException System.out.println(请输入编号:);intnum=
10、input.nextInt();intindex=getper(num);if (index!=-1) System.out.println(此编号已存在!);elseSystem.out.println(请输入XX:);String name=input.next();System.out.println(请输入地址:);String address=input.next();System.out.println(请输入性别:);String sex=input.next();Person person=new Person(num,name,address,sex);List list=g
11、etList();list.add(person);savelist(list);System.out.println(新增成功!); /删除publicvoid delete() throws NumberFormatException,IOException System.out.println(请输入要删除的编号:);intnum=input.nextInt(); List list=getList();booleanflag=false;for(inti=0;ilist.size();i+) Person per=list.get(i);if(num=per.getNum() show
12、Title(); System.out.println(per); System.out.println(是否确定删除Y/N?); String answer=input.next();if(Y.equalsIgnoreCase(answer) list.remove(i); savelist(list); System.out.println(删除成功!); flag=true;break; if (!flag) System.out.println(该客户不存在!); /修改publicvoid update() throws NumberFormatException,IOExcepti
13、on shoAll(); System.out.println(请输入编号:n);intnum=input.nextInt();intId=getper(num);if (Id!=-1) System.out.println(请输入XX:);String name=input.next();System.out.println(请输入地址:);String address=input.next();System.out.println(请输入性别:);String sex=input.next();Listlist=getList();Person per=list.get(Id);per.s
14、etName(name);per.setAddress(address);per.setSex(sex);showTitle();System.out.println(per);savelist(list);System.out.println(修改成功!);else System.out.println(编号不存在!); /查询publicvoid search() throws NumberFormatException,IOException booleanflag=true; Listlist=getList();if(list.size()!=0) while(flag) intsl
15、t=new Menu().subMenu();switch (slt) case 1:System.out.print(t请输入编号:);findId(input.nextInt();break;case 2:System.out.print(t请输入XX:);findName(input.next();break;case 3:System.out.print(t请输入地址:);findAddress(input.next();break;case 4:flag=quit();break;else System.out.println(无任何信息!);/按编号查询publicvoid fin
16、dId(intnum) throws NumberFormatException,IOException Listlist=getList();booleanflag=false;for (inti=0;ilist.size();i+) Person per =list.get(i);if(num=per.getNum() showTitle(); System.out.println(per);flag=true;break; if (!flag) System.out.println(t该客户不存在!); /按XX查询publicvoid findName(String name) thr
17、ows NumberFormatException,IOException Listlist=getList();booleanflag=false;for (inti=0;ilist.size();i+) Person per =list.get(i);if(name.equals(per.getName() showTitle(); System.out.println(per);flag=true;break; if (!flag) System.out.println(t该客户不存在!); /按地址查找publicvoid findAddress(String address) thr
18、ows NumberFormatException,IOException Listlist=getList();booleanflag=false;for (inti=0;ilist.size();i+) Person per =list.get(i);if(address.equals(per.getAddress() showTitle();flag=true; System.out.println(per);break; if (!flag) System.out.println(t该客户不存在!); /退出查询publicboolean quit() System.out.print
19、ln(是否确定退出Y/N?);if (Y.equalsIgnoreCase(input.next() System.out.println(退出成功!);returnfalse;else returntrue; /浏览publicvoid shoAll() throws NumberFormatException,IOException Listlist=getList();if (list.size()!=0) showTitle();for (Person person:list) System.out.println(person.toString();else System.out.p
20、rintln(无任何信息!); publicvoid showTitle() System.out.println(客户信息为:nt编号tXXt地址t性别);/退出系统publicboolean exit() System.out.println(是否确定退出Y/N?);return!Y.equalsIgnoreCase(input.next()?true:false; 4. 测试类class Text:package客户管理系统;import java.io.IOException;publicclass Test publicstaticvoid main(String args) thr
21、ows NumberFormatException,IOException Menu m=new Menu();booleanflag=true;FileOperate fo=new FileOperate();while(flag) intslt=m.showMenu();switch(slt) case 1:fo.insert();/增加break;case 2:fo.delete();/删除break;case 3:fo.update();/修改break;case 4:fo.search();/查询break;case 5:fo.shoAll();/浏览break;case 6: /退出flag=fo.exit();if(!flag)System.out.println(谢谢使用!);break;. .word.