




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、完整代碼:1. 客戶類(class person):package 客戶管理系統(tǒng);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;=name;this.address=address;this.sex=sex;public void setNum(int n
2、um)this.num=num;public int getNum()return num;public void setName(String 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 getSex()return
3、sex;public String toString() return t+num+t+name+t+address+t+sex;2. 菜單類(class Menu):package 客戶管理系統(tǒng);import java.util.Scanner;public class Menu Scanner input=new Scanner(System.in);public Menu() public int showMenu() System.out.println(*);System.out.println(客戶管理系統(tǒng));System.out.println(=);System.out.pri
4、ntln(【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按客戶編號查詢);System.ou
5、t.println(t2按客戶姓名查詢);System.out.println(t3按地址查詢);System.out.println(t4退出);System.out.println(t請選擇查詢編號);return input.nextInt();3. 實際操作類(class FileOperate ):package 客戶管理系統(tǒng);import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IO
6、Exception;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.createNewFil
7、e();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.parseInt(arr0);Stri
8、ng 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 %st rn,c.getNu
9、m(),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 NumberFormatException,IOExcept
10、ion 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(); Person person
11、=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=0;ilist.size(
12、);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(請輸入性別:);String
14、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,IOException boolea
15、n 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();break;case 4:
16、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=true; break; if
17、(!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=true; break;
18、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; System.out.printl
19、n(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=getList(); if (list.size()!=0) showTitle();for (Person person:list) System.out.println(person.toString();else System.out.println(無任何信息!); public vo
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 商標(biāo)使用權(quán)轉(zhuǎn)讓合同(三):長期合作
- 簡易勞動合同簡易合同
- 合同糾紛處理與學(xué)生實踐活動方案
- 水運聯(lián)運代理合同及條款
- 鋼結(jié)構(gòu)加工承攬合同模板
- 林業(yè)用地承包轉(zhuǎn)讓合同樣本
- 大學(xué)合同審簽表
- 抽紗工藝的環(huán)保與可持續(xù)性考核試卷
- 天然氣開采業(yè)的可再生能源轉(zhuǎn)型實踐與方案考核試卷
- 機(jī)床附件的標(biāo)準(zhǔn)化與規(guī)范化生產(chǎn)考核試卷
- 成品半成品倉庫管理制度
- 《產(chǎn)品設(shè)計》(北希望)教學(xué)資料 課程標(biāo)準(zhǔn) 產(chǎn)品設(shè)計課程標(biāo)準(zhǔn)
- 部編版語文四年級下冊第7單元核心素養(yǎng)教案
- 年產(chǎn)2000萬瓶藥食同源飲料生產(chǎn)項目可行性研究報告
- 幼兒園垃圾分類PPT
- 申請?zhí)崛∽》抗e金個人授權(quán)、承諾書(樣表)
- 第4章向量空間課件
- 浸出液的凈化與沉積
- 銀行間本幣市場交易員資格考試真題模擬匯編(共586題)
- 智能制造概論-3 智能制造工藝
- (全冊完整16份)北師大版五年級下冊100道口算題大全
評論
0/150
提交評論