java课程设计客户管理系统源代码.docx
- 文档编号:20124109
- 上传时间:2023-04-25
- 格式:DOCX
- 页数:14
- 大小:17.28KB
java课程设计客户管理系统源代码.docx
《java课程设计客户管理系统源代码.docx》由会员分享,可在线阅读,更多相关《java课程设计客户管理系统源代码.docx(14页珍藏版)》请在冰豆网上搜索。
java课程设计客户管理系统源代码
完整代码:
1.客户类(classperson):
package客户管理系统;
publicclassPerson{
privateintnum;
privateStringname;
privateStringaddress;
privateStringsex;
publicPerson(){}
publicPerson(intnum,Stringname,Stringaddress,Stringsex){
this.num=num;
this.name=name;
this.address=address;
this.sex=sex;
}
publicvoidsetNum(intnum){
this.num=num;
}
publicintgetNum(){
returnnum;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicStringgetName(){
returnname;
}
publicvoidsetAddress(Stringaddress){
this.address=address;
}
publicStringgetAddress(){
returnaddress;
}
publicvoidsetSex(Stringsex){
this.sex=sex;
}
publicStringgetSex(){
returnsex;
}
publicStringtoString(){
return"\t"+num+"\t"+name+"\t"+address+"\t"+sex;
}
}
2.菜单类(classMenu):
package客户管理系统;
importjava.util.Scanner;
publicclassMenu{
Scannerinput=newScanner(System.in);
publicMenu(){}
publicintshowMenu(){
System.out.println("***********************************");
System.out.println("客户管理系统");
System.out.println("===================================");
System.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("请选择操作:
");
returninput.nextInt();
}
publicintsubMenu(){
System.out.println("\t【查询客户】");
System.out.println("\t[1]按客户编号查询");
System.out.println("\t[2]按客户姓名查询");
System.out.println("\t[3]按地址查询");
System.out.println("\t[4]退出");
System.out.println("\t请选择查询编号");
returninput.nextInt();
}
}
3.实际操作类(classFileOperate):
package客户管理系统;
importjava.io.BufferedReader;
importjava.io.File;
importjava.io.FileNotFoundException;
importjava.io.FileReader;
importjava.io.IOException;
importjava.io.PrintWriter;
importjava.util.ArrayList;
importjava.util.List;
importjava.util.Scanner;
publicclassFileOperate{
privatestaticStringINFO="D:
/info.dat";
Filefile=newFile(INFO);
Scannerinput=newScanner(System.in);
publicFileOperate(){
if(!
file.exists()){
try{
file.createNewFile();
}catch(IOExceptione){
e.printStackTrace();
}
}
}
publicList
BufferedReaderbr=newBufferedReader(newFileReader(file));
Stringmsg=null;
List
while((msg=br.readLine())!
=null){
Stringarr[]=msg.split("\t");
intnum=Integer.parseInt(arr[0]);
Stringname=arr[1];
Stringaddress=arr[2];
Stringsex=arr[3];
Personperson=newPerson(num,name,address,sex);
list.add(person);
}
br.close();
returnlist;
}
privatevoidsavelist(List
PrintWriterpw=newPrintWriter(newFile(INFO));
for(Personc:
list){
pw.format("%d\t%s\t%s\t%s\t\r\n",c.getNum(),c.getName(),c.getAddress(),c.getSex());
}
pw.close();
}
publicintgetper(intnum)throwsNumberFormatException,IOException{
List
for(inti=0;i Personper=list.get(i); if(num==per.getNum()){ returni; } } return-1; } //增加 publicvoidinsert()throwsNumberFormatException,IOException{ System.out.println("请输入编号: "); intnum=input.nextInt(); intindex=getper(num); if(index! =-1){ System.out.println("此编号已存在! ");} else{ System.out.println("请输入姓名: "); Stringname=input.next(); System.out.println("请输入地址: "); Stringaddress=input.next(); System.out.println("请输入性别: "); Stringsex=input.next(); Personperson=newPerson(num,name,address,sex); List list.add(person); savelist(list); System.out.println("新增成功! "); } } //删除 publicvoiddelete()throwsNumberFormatException,IOException{ System.out.println("请输入要删除的编号: "); intnum=input.nextInt(); List booleanflag=false; for(inti=0;i Personper=list.get(i); if(num==per.getNum()){ showTitle(); System.out.println(per); System.out.println("是否确定删除(Y/N)? "); Stringanswer=input.next(); if("Y".equalsIgnoreCase(answer)){ list.remove(i); savelist(list); System.out.println("删除成功! "); } flag=true; break; } } if(! flag){ System.out.println("该客户不存在! "); } } //修改 publicvoidupdate()throwsNumberFormatException,IOException{ shoAll(); System.out.println("请输入编号: \n"); intnum=input.nextInt(); intId=getper(num); if(Id! =-1){ System.out.println("请输入姓名: "); Stringname=input.next(); System.out.println("请输入地址: "); Stringaddress=input.next(); System.out.println("请输入性别: "); Stringsex=input.next(); List Personper=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("编号不存在! "); } } //查询 publicvoidsearch()throwsNumberFormatException,IOException{ booleanflag=true; List if(list.size()! =0){ while(flag){ intslt=newMenu().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("无任何信息! "); } } //按编号查询 publicvoidfindId(intnum)throwsNumberFormatException,IOException{ List booleanflag=false; for(inti=0;i Personper=list.get(i); if(num==per.getNum()){ showTitle(); System.out.println(per); flag=true; break; } } if(! flag){ System.out.println("\t该客户不存在! "); } } //按姓名查询 publicvoidfindName(Stringname)throwsNumberFormatException,IOException{ List booleanflag=false; for(inti=0;i Personper=list.get(i); if(name.equals(per.getName())){ showTitle(); System.out.println(per); flag=true; break; } } if(! flag){ System.out.println("\t该客户不存在! "); } } //按地址查找 publicvoidfindAddress(Stringaddress)throwsNumberFormatException,IOException{ List booleanflag=false; for(inti=0;i Personper=list.get(i); if(address.equals(per.getAddress())){ showTitle(); flag=true; System.out.println(per); break; } } if(! flag){ System.out.println("\t该客户不存在! "); } } //退出查询 publicbooleanquit(){ System.out.println("是否确定退出(Y/N)? "); if("Y".equalsIgnoreCase(input.next())){ System.out.println("退出成功! "); returnfalse; }else{ returntrue; } } //浏览 publicvoidshoAll()throwsNumberFormatException,IOException{ List if(list.size()! =0){ showTitle(); for(Personperson: list){ System.out.println(person.toString()); } }else{ System.out.println("无任何信息! "); } } publicvoidshowTitle(){ System.out.println("客户信息为: \n\t编号\t姓名\t地址\t性别"); } //退出系统 publicbooleanexit(){ System.out.println("是否确定退出(Y/N)? "); return! "Y".equalsIgnoreCase(input.next())? true: false; } } 4.测试类(classText): package客户管理系统; importjava.io.IOException; publicclassTest{ publicstaticvoidmain(String[]args)throwsNumberFormatException, IOException{ Menum=newMenu(); booleanflag=true; FileOperatefo=newFileOperate(); while(flag){ intslt=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; } } } }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 课程设计 客户 管理 系统 源代码
![提示](https://static.bdocx.com/images/bang_tan.gif)