java课程设计 客户管理系统源代码Word格式.docx

上传人:b****6 文档编号:22225830 上传时间:2023-02-03 格式:DOCX 页数:14 大小:17.28KB
下载 相关 举报
java课程设计 客户管理系统源代码Word格式.docx_第1页
第1页 / 共14页
java课程设计 客户管理系统源代码Word格式.docx_第2页
第2页 / 共14页
java课程设计 客户管理系统源代码Word格式.docx_第3页
第3页 / 共14页
java课程设计 客户管理系统源代码Word格式.docx_第4页
第4页 / 共14页
java课程设计 客户管理系统源代码Word格式.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

java课程设计 客户管理系统源代码Word格式.docx

《java课程设计 客户管理系统源代码Word格式.docx》由会员分享,可在线阅读,更多相关《java课程设计 客户管理系统源代码Word格式.docx(14页珍藏版)》请在冰豆网上搜索。

java课程设计 客户管理系统源代码Word格式.docx

publicvoidsetSex(Stringsex){

publicStringgetSex(){

returnsex;

publicStringtoString(){

return"

\t"

+num+"

+name+"

+address+"

+sex;

}

}

2.菜单类(classMenu):

importjava.util.Scanner;

publicclassMenu{

Scannerinput=newScanner(System.in);

publicMenu(){}

publicintshowMenu(){

System.out.println("

***********************************"

);

客户管理系统"

==================================="

【1】增加"

【2】删除"

【3】修改"

【4】查询"

【5】浏览"

【6】退出"

System.out.print("

请选择操作:

"

returninput.nextInt();

publicintsubMenu(){

\t【查询客户】"

\t[1]按客户编号查询"

\t[2]按客户姓名查询"

\t[3]按地址查询"

\t[4]退出"

\t请选择查询编号"

3.实际操作类(classFileOperate):

importjava.io.BufferedReader;

importjava.io.File;

importjava.io.FileNotFoundException;

importjava.io.FileReader;

importjava.io.IOException;

importjava.io.PrintWriter;

importjava.util.ArrayList;

importjava.util.List;

publicclassFileOperate{

privatestaticStringINFO="

D:

/info.dat"

;

Filefile=newFile(INFO);

publicFileOperate(){

if(!

file.exists()){

try{

file.createNewFile();

}catch(IOExceptione){

e.printStackTrace();

publicList<

Person>

getList()throwsNumberFormatException,IOException{

BufferedReaderbr=newBufferedReader(newFileReader(file));

Stringmsg=null;

List<

list=newArrayList<

();

while((msg=br.readLine())!

=null){

Stringarr[]=msg.split("

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<

list)throwsFileNotFoundException{

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<

list=getList();

for(inti=0;

i<

list.size();

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();

请输入地址:

Stringaddress=input.next();

请输入性别:

Stringsex=input.next();

Personperson=newPerson(num,name,address,sex);

List<

list.add(person);

savelist(list);

新增成功!

//删除

publicvoiddelete()throwsNumberFormatException,IOException{

请输入要删除的编号:

booleanflag=false;

for(inti=0;

Personper=list.get(i);

if(num==per.getNum()){

showTitle();

System.out.println(per);

是否确定删除(Y/N)?

Stringanswer=input.next();

if("

Y"

.equalsIgnoreCase(answer)){

list.remove(i);

savelist(list);

System.out.println("

删除成功!

}

flag=true;

break;

}

if(!

flag){

该客户不存在!

//修改

publicvoidupdate()throwsNumberFormatException,IOException{

shoAll();

\n"

intnum=input.nextInt();

intId=getper(num);

if(Id!

请输入姓名:

Stringname=input.next();

请输入地址:

Stringaddress=input.next();

请输入性别:

Stringsex=input.next();

list=getList();

Personper=list.get(Id);

per.setName(name);

per.setAddress(address);

per.setSex(sex);

showTitle();

System.out.println(per);

savelist(list);

修改成功!

}else{

编号不存在!

//查询

publicvoidsearch()throwsNumberFormatException,IOException{

booleanflag=true;

if(list.size()!

=0){

while(flag){

intslt=newMenu().subMenu();

switch(slt){

case1:

System.out.print("

\t请输入编号:

findId(input.nextInt());

case2:

\t请输入姓名:

findName(input.next());

break;

case3:

\t请输入地址:

findAddress(input.next());

case4:

flag=quit();

}else{

无任何信息!

//按编号查询

publicvoidfindId(intnum)throwsNumberFormatException,IOException{

booleanflag=false;

for(inti=0;

Personper=list.get(i);

showTitle();

System.out.println(per);

flag=true;

break;

}

\t该客户不存在!

//按姓名查询

publicvoidfindName(Stringname)throwsNumberFormatException,IOException{

if(name.equals(per.getName())){

//按地址查找

publicvoidfindAddress(Stringaddress)throwsNumberFormatException,IOException{

if(address.equals(per.getAddress())){

flag=true;

break;

//退出查询

publicbooleanquit(){

是否确定退出(Y/N)?

if("

.equalsIgnoreCase(input.next())){

退出成功!

returnfalse;

returntrue;

//浏览

publicvoidshoAll()throwsNumberFormatException,IOException{

if(list.size()!

for(Personperson:

System.out.println(person.toString());

publicvoidshowTitle(){

客户信息为:

\n\t编号\t姓名\t地址\t性别"

//退出系统

publicbooleanexit(){

return!

.equalsIgnoreCase(input.next())?

true:

false;

4.测试类(classText):

publicclassTest{

publicstaticvoidmain(String[]args)throwsNumberFormatException,

IOException{

Menum=newMenu();

FileOperatefo=newFileOperate();

while(flag){

intslt=m.showMenu();

switch(slt){

case1:

fo.insert();

case2:

fo.delete();

//删除

case3:

fo.update();

case4:

fo.search();

//查询

case5:

fo.shoAll();

//浏览

case6:

//退出

flag=fo.exit();

if(!

flag)

谢谢使用!

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 商务科技

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1