




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
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
2、num)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("*");Sy
4、stem.out.println("客戶管理系統(tǒng)");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】退出");S
5、ystem.out.println("*");System.out.print("請(qǐng)選擇操作:");return input.nextInt();public int subMenu() System.out.println("t【查詢客戶】");System.out.println("t1按客戶編號(hào)查詢");System.out.println("t2按客戶姓名查詢");System.out.println("t3按地址查詢");System.out.println(&qu
6、ot;t4退出");System.out.println("t請(qǐng)選擇查詢編號(hào)");return input.nextInt();3. 實(shí)際操作類(class FileOperate ):package 客戶管理系統(tǒng);import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.io.PrintWriter;import jav
7、a.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.createNewFile();catch(IOException e) e.printStac
8、kTrace();public List<Person> getList() throws NumberFormatException,IOExceptionBufferedReader br=new BufferedReader(new FileReader(file);String msg=null;List<Person> list =new ArrayList<Person>();while (msg =br.readLine()!=null) String arr=msg.split("t");int num=Integer.p
9、arseInt(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<Person> list)throws FileNotFoundExceptionPrintWriter pw=new PrintWriter(new File(INFO);for (Person c:list) pw.f
10、ormat("%dt %st %st %st rn",c.getNum(),c.getName(),c.getAddress(),c.getSex();pw.close(); public int getper(int num) throws NumberFormatException,IOException List<Person> list=getList(); for (int i=0;i<list.size();i+) Person per=list.get(i); if(num=per.getNum() return i; return -1;
11、/增加 public void insert() throws NumberFormatException,IOException System.out.println("請(qǐng)輸入編號(hào):"); int num=input.nextInt(); int index=getper(num); if (index!=-1) System.out.println("此編號(hào)已存在!"); elseSystem.out.println("請(qǐng)輸入姓名:");String name=input.next();System.out.println(&qu
12、ot;請(qǐng)輸入地址:");String address=input.next();System.out.println("請(qǐng)輸入性別:");String sex=input.next(); Person person=new Person(num,name,address,sex);List<Person> list=getList();list.add(person);savelist(list);System.out.println("新增成功!"); /刪除 public void delete() throws NumberF
13、ormatException,IOException System.out.println("請(qǐng)輸入要?jiǎng)h除的編號(hào):"); int num=input.nextInt(); List<Person> 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); System.out.println("是否確定刪除(Y/
14、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 NumberFormatException,IOException shoAll(); S
15、ystem.out.println("請(qǐng)輸入編號(hào):n"); int num=input.nextInt(); int Id=getper(num); if (Id!=-1) System.out.println("請(qǐng)輸入姓名:");String name=input.next();System.out.println("請(qǐng)輸入地址:");String address=input.next();System.out.println("請(qǐng)輸入性別:");String sex=input.next();List<P
16、erson>list=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("編號(hào)不存在!"); /查詢 public void search() throws NumberFormatException,IOExce
17、ption boolean flag=true; List<Person>list=getList(); if(list.size()!=0) while(flag) int slt=new Menu().subMenu();switch (slt) case 1:System.out.print("t請(qǐng)輸入編號(hào):");findId(input.nextInt();break;case 2:System.out.print("t請(qǐng)輸入姓名:");findName(input.next();break;case 3:System.out.pri
18、nt("t請(qǐng)輸入地址:");findAddress(input.next();break;case 4:flag=quit();break;else System.out.println("無(wú)任何信息!");/按編號(hào)查詢 public void findId(int num) throws NumberFormatException,IOException List<Person>list=getList(); boolean flag=false; for (int i=0;i<list.size();i+) Person per =
19、list.get(i); if(num=per.getNum() showTitle(); System.out.println(per); flag=true; break; if (!flag) System.out.println("t該客戶不存在!"); /按姓名查詢 public void findName(String name) throws NumberFormatException,IOException List<Person>list=getList(); boolean flag=false; for (int i=0;i<list
20、.size();i+) Person per =list.get(i); if(name.equals(per.getName() showTitle(); System.out.println(per); flag=true; break; if (!flag) System.out.println("t該客戶不存在!"); /按地址查找 public void findAddress(String address) throws NumberFormatException,IOException List<Person>list=getList(); boo
21、lean 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() System.out.println("是否確定退出(Y/N)?");if (&qu
22、ot;Y".equalsIgnoreCase(input.next() System.out.println("退出成功!");return false;else return true; /瀏覽 public void shoAll() throws NumberFormatException,IOException List<Person>list=getList(); if (list.size()!=0) showTitle();for (Person person:list) System.out.println(person.toString();else System.out
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 城管洪災(zāi)搶險(xiǎn)方案(3篇)
- 內(nèi)部審計(jì)面試題及答案
- 現(xiàn)代車輛收售方案
- 甲狀腺手術(shù)并發(fā)癥
- 場(chǎng)監(jiān)督管理局建設(shè)項(xiàng)目施工許可合同示范文本
- 期權(quán)產(chǎn)品面試題及答案
- 綏化中考試題及答案
- 北方小區(qū)綠化改造方案
- 銷售內(nèi)勤考試題及答案
- 票務(wù)崗位面試題及答案
- 急性胃腸炎的護(hù)理查房
- 第一章-護(hù)理學(xué)基礎(chǔ)緒論
- 煙花爆竹經(jīng)營(yíng)單位安全管理人員培訓(xùn)教材課件
- J波與J波綜合征課件
- 微整面部美學(xué)設(shè)計(jì)面部風(fēng)水設(shè)計(jì)課件
- 5噸龍門吊安裝與拆除專項(xiàng)施工方案
- 康復(fù)科護(hù)理質(zhì)量監(jiān)測(cè)指標(biāo)
- 農(nóng)藥基本常識(shí)課件
- 六年級(jí)數(shù)學(xué)分?jǐn)?shù)除法、解方程計(jì)算題 (含答案)
- 高速鐵路竣工驗(yàn)收辦法
- 擬投入公路工程施工設(shè)備檢測(cè)儀器設(shè)備表
評(píng)論
0/150
提交評(píng)論