《java课程设计——客户管理系统源代码(共17页).docx》由会员分享,可在线阅读,更多相关《java课程设计——客户管理系统源代码(共17页).docx(17页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
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 num,String name,String address,String sex)this.num=num;this.name=name;this.address=address;this.sex=sex;public void
2、 setNum(int num)this.num=num;public int getNum()return num;public void setName(String name)this.name=name;public String getName()return name;public void setAddress(String address)this.address=address;public String getAddress()return address;public void setSex(String sex)this.sex=sex;public String ge
3、tSex()return sex;public String toString() return t+num+t+name+t+address+t+sex;2. 菜单类(class Menu):package 客户管理系统;import java.util.Scanner;public class Menu Scanner input=new Scanner(System.in);public Menu() public int showMenu() System.out.println(*);System.out.println(客户管理系统);System.out.println(=);S
4、ystem.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(请选择操作:);return input.nextInt();public int subMenu() System.out.println(t【查询客户】);System.out.println(t1按客户编号
5、查询);System.out.println(t2按客户姓名查询);System.out.println(t3按地址查询);System.out.println(t4退出);System.out.println(t请选择查询编号);return input.nextInt();3. 实际操作类(class FileOperate ):package 客户管理系统;import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;impo
6、rt 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 = new File(INFO);Scanner input=new Scanner(System.in);public FileOperate() if (!file.exists() try file
7、.createNewFile();catch(IOException e) e.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);int num=Integer.parseI
8、nt(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;private void savelist(List list)throws FileNotFoundExceptionPrintWriter pw=new PrintWriter(new File(INFO);for (Person c:list) pw.format(%dt %st %st %
9、st rn,c.getNum(),c.getName(),c.getAddress(),c.getSex();pw.close(); public int getper(int num) throws NumberFormatException,IOException List list=getList(); for (int i=0;ilist.size();i+) Person per=list.get(i); if(num=per.getNum() return i; return -1; /增加 public void insert() throws NumberFormatExcep
10、tion,IOException System.out.println(请输入编号:); int num=input.nextInt(); int index=getper(num); if (index!=-1) System.out.println(此编号已存在!); elseSystem.out.println(请输入姓名:);String name=input.next();System.out.println(请输入地址:);String address=input.next();System.out.println(请输入性别:);String sex=input.next();
11、Person person=new Person(num,name,address,sex);List list=getList();list.add(person);savelist(list);System.out.println(新增成功!); /删除 public void delete() throws NumberFormatException,IOException System.out.println(请输入要删除的编号:); int num=input.nextInt(); List list=getList(); boolean flag=false; for(int i=
12、0;ilist.size();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(
13、该客户不存在!); /修改 public void 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(请输
14、入性别:);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(编号不存在!); /查询 public void search() throws NumberFormatException,IOExc
15、eption boolean flag=true; Listlist=getList(); if(list.size()!=0) while(flag) int slt=new Menu().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();
16、break;case 4:flag=quit();break;else System.out.println(无任何信息!);/按编号查询 public void findId(int num) throws NumberFormatException,IOException Listlist=getList(); boolean flag=false; for (int i=0;ilist.size();i+) Person per =list.get(i); if(num=per.getNum() showTitle(); System.out.println(per); flag=tru
17、e; break; if (!flag) System.out.println(t该客户不存在!); /按姓名查询 public void findName(String name) throws NumberFormatException,IOException Listlist=getList(); boolean flag=false; for (int i=0;ilist.size();i+) Person per =list.get(i); if(name.equals(per.getName() showTitle(); System.out.println(per); flag=
18、true; break; if (!flag) System.out.println(t该客户不存在!); /按地址查找 public void findAddress(String address) throws NumberFormatException,IOException Listlist=getList(); boolean flag=false; for (int i=0;ilist.size();i+) Person per =list.get(i); if(address.equals(per.getAddress() showTitle(); flag=true; Syst
19、em.out.println(per); break; if (!flag) System.out.println(t该客户不存在!); /退出查询 public boolean quit() System.out.println(是否确定退出(Y/N)?);if (Y.equalsIgnoreCase(input.next() System.out.println(退出成功!);return false;else return true; /浏览 public void shoAll() throws NumberFormatException,IOException Listlist=ge
20、tList(); if (list.size()!=0) showTitle();for (Person person:list) System.out.println(person.toString();else 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(
21、)?true:false; 4. 测试类(class Text):package 客户管理系统;import java.io.IOException;public class Test public static void main(String args) throws NumberFormatException,IOException Menu m=new Menu();boolean flag=true;FileOperate fo=new FileOperate();while(flag) int slt=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;专心-专注-专业
限制150内