《java课程设计_客户管理系统源代码.pdf》由会员分享,可在线阅读,更多相关《java课程设计_客户管理系统源代码.pdf(11页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、 完整代码:1.客户类(class person)package 客户管理系统;public class Person(private int num private String name private String address;private String sex;public Person()public Person(int numString nameString sex)this.num=num this.name=name this.address=address;this.sex=sex;public void setNum(int nun)this.num=num pu
2、blic int getNum()return num public void setName(String nam this.name=name public String getName()return name public void setAddress(String address)this.address=address;public String getAddress()return address;address,String public void setSex(String sex)(this.sex=sex;public String getSex()(return se
3、x;public String toString()(return t+num+t+nameJt+address+t+sex;2.菜单类(class Menu):package 客户管理系统;import java.util.Scanner;public class Menu(Scanner input=newScanner(System.in);public Menu()(public int showMenu()(System.out.println();System.out.println(System.out.println();System.out.println(System.ou
4、t.println(System.out.println(System.out.println(System.out.println(System.out.println(System.out.println();”客户管理系统);【1】增加);【2】删除);【3】修改);【4】查询);”【5】浏览);【6】退出”);*System.out.print(请选择操作:);3.实际操作类(class FileOperate):package 客户管理系统;import java.io.BufferedReader;import java.io.File;import java.io.FileNot
5、FoundException;import java.io.FileReader;import java.io.IOException;import java.io.PrintWriter;import java.util.ArrayList;import java.util.List;import java.util.Scanner;public class FileOperate(private static String INFO=D:/info.dat File file=newFile(INFC);Scanner input=newScanner(System.in);public
6、FileOperate()(if(!file.exists()(try(file.createNewFile();return input.nextInt();public int subMenu()(System.out.println(System.out.println(System.out.println(System.out.println(System.out.println(System.out.println(return t【查询客户】);t1 按客户编号查询)t2 按客户姓名查询)t3 按地址查询);t4退出);t 请选择查询编号);input.nextInt();catc
7、h(lOException e)(e.printStackTrace();public List getList()throws NumberFormatException,IOException BufferedReader br=new BufferedReader(new FileReader(file);String msg=null;List list=newArrayList();while(msg=br.readLine()!=null)String arr=msgsplit(t);int num=Integer.parseInt(arr 0);String name=arr 1
8、;String address=arr 2;String sex=arr 3;Person person=new Person(num name address,sex);list.add(person);br.close();return list;private void savelist(List list)throws FileNotFoundException PrintWriter pw=new PrintWriter(newFile(INFO);for(Person c:list)pwformat(%dt%st%st%st rn,c.getNum(),c.getName(),c.
9、getAddress(),c.getSex();pwclose();public int getper(int num)throws NumberFormatException,IOException List list=getList();for(int i=0;i list.size();i+)(Person per=list.get(i);if(num=per.getNum()(return i;return-1;增加 public void insert()throws NumberFormatException,IOException System.out.println(请输入编号
10、:);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=newPerson(num name address,sex);L
11、ist list=getList();list.add(person);savelist(list);System.out.println(新增成功!);/删除 public void delete()throws NumberFormatException,IOException(System.out.println(请输入要删除的编号:);int nun=input.nextInt();List list=getList();boolean flag=false;for(int i=0;i list.size();i+)(Person per=list.get(i);if(nun=per.
12、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(该客户不存在!);/修改 public void update()throws NumberFormatExcept
13、ion,IOException(shoAll();System.out.println(请输入编号:n);int num=input.nextInt();int Id=getper(nun);if(Id!=-1)(System.out.println(请输入姓名:);String name=input.next();System.out.println(请输入地址:);String address=input.next();System.out.println(请输入性别:”);String sex=input.next();List list=getList();Person per=lis
14、t.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(编号不存在!);/查询 public void search()throws NumberFormatException,IOException boolean flag=true;List list=getList();if(list.size()!=0)whi
15、le(flag)int slt=newMenu().subMenu();switch(slt)case 1:System.out.print(t 请输入编号:);findId(input.nextInt();break;case 2:System.out.print(t 请输入姓名:);findName(input.next();break;case 3:System.out.print(t 请输入地址:);findAddress(input.next();break;case 4:flag=quit();break;else System.out.println(无任何信息!);/按编号查询
16、 public void findId(int nun)throws NumberFormatException,IOException List list=getList();boolean flag=false;for(int i=0;i list.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 该客户不存在!);/按姓名查询 public void findName(St
17、ring nam。throws NumberFormatException,IOException(List list=getList();boolean flag=false;for(int i=0;i list.size();i+)(Person per=list.get(i);if(nameequals(per.getName()(showTitle();System.out.println(per);flag=true;break;if(!flag)(System.out.println(t 该客户不存在!);/按地址查找 public void findAddress(String
18、address)throws NumberFormatException,IOException(List list=getList();boolean flag=false;for(int i=0;i list.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 该客户不存在!);/退出查询 public boolean quit()(Syst
19、em.out.println(是否确定退出(Y/N)?”);if(Y”.equalsIgnoreCase(input.next()(System.out.println(退出成功!);return false;else(return true;/浏览 public void shoAll()throws NumberFormatException,IOException List list=getList();if(list.size()!=0)showTitle();for(Person person:list)System.out.println(person.toString();els
20、e System.out.println(无任何信息!);public void showTitle()System.out.println(客户信息为:nt 编号t 姓名t 地址 t 性别”);/退出系统 public boolean exit()System.out.println(是否确定退出(Y/N)?”);return!”Y”.equalsIgnoreCase(input.next()?true:false 4.测试类(class Text):package 客户管理系统;import java.io.IOException;public class Test(public stat
21、ic void main(String args)throws NumberFormatException,lOException(Menu m=new Menu();boolean flag=true;FileOperate fo=new FileOperate();while(flag)(int slt=mshowMenu();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;