




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(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) ;publicclass Person privateintnum;privateStringname;privateStringaddress ;privateStringsex;publicPerson()publicPerson( intnum,Stringname,Stringaddress ,Stringsex)this . num=num;this . name=name;this . address =address ;this . sex=sex;publicvoid setNum( i
2、ntnum)this . num=num;publicintgetNum()returnnum;publicvoid setName(Stringname)this . name=name;publicString getName()returnname;publicvoid setAddress(Stringaddress )this . address =address ;publicString getAddress()returnaddress ;.專業(yè) .整理 .下載可編輯publicvoid setSex(Stringsex)this . sex=sex;publicString
3、getSex()returnsex;publicString toString() return"t"+num+"t"+name+"t"+address +"t"+sex;2.菜單類 (class Menu) :package 客戶管理系統(tǒng) ;publicclass Menu Scanner input =new Scanner(System. in );publicMenu() publicintshowMenu() System. out .println("*");System. out
4、.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 .prin
5、tln(" 【6】退出 " );System. out .println("*");System. out .print(" 請(qǐng)選擇操作: " );.專業(yè) .整理 .下載可編輯returninput .nextInt();public int subMenu() System. out .println("t 【查詢客戶】 " );System. out .println("t1按客戶編號(hào)查詢 " );System. out .println("t2按客戶姓名查詢 " );S
6、ystem. out .println("t3按地址查詢 " );System. out .println("t4退出");System. out .println("t 請(qǐng)選擇查詢編號(hào) ");returninput .nextInt();3. 實(shí)際操作類( classFileOperate):package 客戶管理系統(tǒng) ;publicclass FileOperate privatestaticStringINFO="D:/info.dat"Filefile=new File(INFO);Scanner inp
7、ut =new Scanner(System. in );publicFileOperate() if(! file.exists() .專業(yè) .整理 .下載可編輯try file.createNewFile(); catch (IOExceptione) e.printStackTrace();publicList<Person> getList()throwsNumberFormatException,IOExceptionBufferedReader br =new BufferedReader( new FileReader( file );Stringmsg=null;L
8、ist<Person>list= new ArrayList<Person>();while ( msg = br .readLine()!=null ) Stringarr = msg.split("t");intnum=Integer.parseInt ( arr 0);Stringname= arr 1;Stringaddress =arr 2;Stringsex=arr 3;Person person = new Person( num, name, address , sex);list.add( person );br .close();
9、returnlist;privatevoid savelist(List<Person>list) throwsFileNotFoundExceptionnew File( INFO);PrintWriterpw=new PrintWriter(for(Personc: list ) pw.format("%dt %st %st %strn" , c.getNum(), c.getName(), c.getAddress(),c.getSex();pw.close();public int getper( int num) throws NumberFormat
10、Exception,IOException.專業(yè) .整理 .下載可編輯List<Person>list=getList();for ( inti =0; i <list.size();i +) Person per =list.get( i );if ( num=per .getNum() returni ;return-1;/ 增加publicvoid insert()throwsNumberFormatException,IOExceptionSystem. out .println(" 請(qǐng)輸入編號(hào): " );intnum=input .nextInt
11、();intindex =getper( num);if( index !=-1) System. out .println(" 此編號(hào)已存在! " );else System. out .println(" 請(qǐng)輸入姓名: " );Stringname=input .next();System. out .println(" 請(qǐng)輸入地址: " );Stringaddress =input .next();System. out .println(" 請(qǐng)輸入性別: " );Stringsex=input .next(
12、);Person person =new Person( num, name, address , sex); List<Person> list =getList();list.add( person );savelist(list);System. out .println(" 新增成功! " );/ 刪除.專業(yè) .整理 .下載可編輯publicvoid delete()throwsNumberFormatException,IOExceptionSystem. out .println(" 請(qǐng)輸入要?jiǎng)h除的編號(hào): " );intnum=i
13、nput .nextInt();List<Person>list=getList();boolean flag =false ;for ( inti =0; i <list.size();i +) Person per=list.get( i );if ( num=per .getNum() showTitle();System. out .println(per );System. out .println(" 是否確定刪除( Y/N)? " );Stringanswer=input .next();if ( "Y" .equalsI
14、gnoreCase(answer) list.remove( i );savelist(list);System. out .println(" 刪除成功 !" );flag =true ;break ;if(! flag ) System. out .println(" 該客戶不存在! " );/ 修改publicvoid update()throwsNumberFormatException,IOExceptionshoAll();System.out .println(" 請(qǐng)輸入編號(hào): n" );intnum=input .ne
15、xtInt();intId =getper( num);if( Id !=-1) System. out .println(" 請(qǐng)輸入姓名 :" );Stringname=input .next();.專業(yè) .整理 .下載可編輯System. out .println(" 請(qǐng)輸入地址 :" );Stringaddress =input .next();System. out .println(" 請(qǐng)輸入性別 :" );Stringsex=input .next();List<Person> list=getList();P
16、erson 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() throwsNumberFormatException,IOExceptio
17、nboolean flag =true ;List<Person> list=getList();if ( list.size()!=0) while ( flag ) intslt =new Menu().subMenu();switch ( slt ) case 1:System. out .print("t請(qǐng)輸入編號(hào): ");findId(input .nextInt();break ;case 2:.專業(yè) .整理 .下載可編輯System. out .print("t請(qǐng)輸入姓名: ");findName( input .next();
18、break ;case 3:System. out .print("t請(qǐng)輸入地址: ");findAddress(input .next();break ;case 4: flag =quit();break ; else System. out .println(" 無任何信息! " );/ 按編號(hào)查詢public void findId( int num) throws NumberFormatException,IOExceptionList<Person>list=getList();booleanflag =false ;for(
19、inti =0; i <list.size();i +) Person per = list.get( i );if ( num=per .getNum() showTitle();System. out .println(per);flag =true ;break ;if(! flag ) System.out .println("t該客戶不存在! " );.專業(yè) .整理 .下載可編輯/ 按姓名查詢publicvoid findName(Stringname) throwsNumberFormatException,IOExceptionList<Perso
20、n>list=getList();booleanflag =false ;for( inti =0; i <list.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該客戶不存在! " );/ 按地址查找publicvoid findAddress(Stringaddress ) thro
21、wsNumberFormatException,IOExceptionList<Person>list=getList();booleanflag =false ;for ( inti =0; i <list.size();i +) Personper = list.get( i );if ( address .equals( per .getAddress() showTitle();flag =true ;System. out .println(per );break ;.專業(yè) .整理 .下載可編輯if(! flag ) System.out .println(&quo
22、t;t該客戶不存在! " );/ 退出查詢publicboolean quit() System. out .println(" 是否確定退出( Y/N)? " );if( "Y" .equalsIgnoreCase(input .next() System. out .println(" 退出成功! " );returnfalse ; else returntrue ;/ 瀏覽publicvoid shoAll()throwsNumberFormatException,IOExceptionList<Person>list=getList();if( list.size()!=0) showTitle();for (Personperson : list) System. out .println(person .toString(); else System. out .println(" 無任何信息! " );publ
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年注冊(cè)稅務(wù)師稅法一高效備考:模擬試卷與解題技巧
- 中式快餐連鎖創(chuàng)業(yè)計(jì)劃書
- 2025年西班牙語DELE考試真題卷:閱讀理解與寫作專項(xiàng)訓(xùn)練
- 框架剪力墻高層住宅實(shí)測(cè)實(shí)量細(xì)則交底(多圖)
- 膩?zhàn)庸瓮颗嘤?xùn)
- 古文明遺產(chǎn)解讀
- 手術(shù)部位感染的預(yù)防與控制
- 幾何圖形解密
- 胃癱置營(yíng)養(yǎng)管后護(hù)理
- 物業(yè)消防安全教育培訓(xùn)
- 2024年北京市重點(diǎn)建設(shè)項(xiàng)目政府投資計(jì)劃項(xiàng)目
- 金屬冶煉安全事故案例與分析
- 《柯高峰行政監(jiān)察學(xué)》課件
- 2024城市道路路面維修養(yǎng)護(hù)技術(shù)規(guī)程
- 老年糖尿病夜間低血糖的預(yù)防及護(hù)理
- 梅毒病人產(chǎn)后護(hù)理查房
- 小班-語言社會(huì)-幸福的“叮咚”-課件(基礎(chǔ)版)公開課教案教學(xué)設(shè)計(jì)課件案例試卷
- 專業(yè)培訓(xùn)金蝶k3wise供應(yīng)鏈系統(tǒng)培訓(xùn)
- 辦公耗材采購(gòu) 投標(biāo)方案(技術(shù)方案)
- 《干部履歷表》填寫樣式
- 汽車電氣設(shè)備檢測(cè)與維修中職全套教學(xué)課件
評(píng)論
0/150
提交評(píng)論