java课程设计客户管理系统源代码.docx
java课程设计客户管理系统源代码 完整代码: 1.客户类(classperson): package客户管理系统; publicclass Person privateint num; private String name; private String address; private String sex; public Person() public Person(int num,String name,String address,String sex) this.num=num; =name; this.address=address; this.sex=sex; publicvoid setNum(int num) this.num=num; publicint getNum() return num; publicvoid setName(String name) =name; public StringgetName() return name; publicvoid setAddress(String address) this.address=address; public StringgetAddress() return address; publicvoid setSex(String sex) this.sex=sex; public StringgetSex() return sex; public StringtoString() return"t"+num+"t"+name+"t"+address+"t"+sex; 2.菜单类(classMenu): package客户管理系统; import publicclass Menu Scanner input=new Scanner(System.in); public Menu() publicint showMenu() System.out.println("*"); System.out.println("客户管理系统"); System.out.println("="); System.out.println("增加"); System.out.println("删除"); System.out.println("修改"); System.out.println("查询"); System.out.println("浏览"); System.out.println("退出"); System.out.println("*"); System.out.print("请选择操作:"); return input.nextInt(); publicint subMenu() System.out.println("t"); System.out.println("t1按客户编号查询"); System.out.println("t2按客户姓名查询"); System.out.println("t3按地址查询"); System.out.println("t4退出"); System.out.println("t请选择查询编号"); return input.nextInt(); 3.实际操作类(classFileOperate):package客户管理系统; import import import import import import import import 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.printStackTrace(); public ListgetList()throws NumberFormatException,IOException BufferedReader br=new BufferedReader(new FileReader(file); String msg=null; Listlist=new ArrayList(); while(msg=br.readLine()!=null) String arr=msg.split("t"); int num=Integer.parseInt(arr0); String name=arr1; String address=arr2; String sex=arr3; Person person=new Person(num,name,address,sex); list.add(person); br.close(); return list; privatevoid savelist(Listlist)throws FileNotFoundExceptio n PrintWriter pw=new PrintWriter(new File(INFO); for(Person c:list) pw.format("%dt%st%st%strn",c.getNum(),c.getName(),c.getAd dress(),c.getSex(); pw.close(); publicint getper(int num)throws NumberFormatException,IOException Listlist=getList(); for(int i=0;i Person per=list.get(i); if(num=per.getNum() return i; return-1; /增加 publicvoid insert()throws NumberFormatException,IOException System.out.println("请输入编号:"); int num=input.nextInt(); int index=getper(num); if(index!=-1) System.out.println("此编号已存在!"); else System.out.println("请输入姓名:"); 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); Listlist=getList(); list.add(person); savelist(list); System.out.println("新增成功!"); /删除 publicvoid delete()throws NumberFormatException,IOException System.out.println("请输入要删除的编号:"); int num=input.nextInt(); Listlist=getList(); boolean flag=false; for(int i=0;i Person per=list.get(i); if(num=per.getNum() showTitle(); 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,IOException shoAll(); System.out.println("请输入编号:n"); int num=input.nextInt(); int Id=getper(num); if(Id!=-1) System.out.println("请输入姓名:"); 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.setName(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 boolean flag=true; Listlist=getList(); if(list.size()!=0) while(flag) int slt=new Menu().subMenu(); switch(slt) case1: System.out.print("t请输入编号:"); findId(input.nextInt(); break; case2: System.out.print("t请输入姓名:"); findName(input.next(); break; case3: System.out.print("t请输入地址:"); findAddress(input.next(); break; case4:flag=quit(); break; else System.out.println("无任何信息!"); /按编号查询 publicvoid findId(int num)throws NumberFormatException,IOException Listlist=getList(); boolean flag=false; for(int i=0;i Person per=list.get(i); if(num=per.getNum() showTitle(); System.out.println(per); flag=true; break; if(!flag) System.out.println("t该客户不存在!"); /按姓名查询 publicvoid findName(String name)throws NumberFormatException,IOExcept ion Listlist=getList(); boolean flag=false; for(int i=0;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)throws NumberFormatException,IO Exception Listlist=getList(); boolean flag=false; for(int i=0;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.println("是否确定退出(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.println("无任何信息!"); publicvoid showTitle() System.out.println("客户信息为:nt编号t姓名t地址t性别"); /退出系统 publicboolean exit() System.out.println("是否确定退出(Y/N)?"); return!"Y".equalsIgnoreCase(input.next()?true:false; 4.测试类(classText): package客户管理系统; import publicclass Test publicstaticvoid main(Stringargs)throws NumberFormatException, IOException Menu m=new Menu(); boolean flag=true; FileOperate fo=new FileOperate(); while(flag) int slt=m.showMenu(); switch(slt) case1:fo.insert();/增加 break; case2:fo.delete();/删除 break; case3:fo.update();/修改 break; case4:fo.search();/查询 break; case5:fo.shoAll();/浏览 break; case6:/退出 flag=fo.exit(); if(!flag) System.out.println("谢谢使用!"); break;