java課程設(shè)計(jì)——客戶管理系統(tǒng)源代碼_第1頁(yè)
java課程設(shè)計(jì)——客戶管理系統(tǒng)源代碼_第2頁(yè)
java課程設(shè)計(jì)——客戶管理系統(tǒng)源代碼_第3頁(yè)
已閱讀5頁(yè),還剩11頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(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) ;public class Person privateint num;privateStringname;privateStringaddress ;privateStringsex;public Person()public Person( int num,String name,String address ,String sex)this . num=num;this . name=name;this . address =address ;this . sex =sex ;public void setN

2、um( int num)this . num=num;public int getNum()return num;public void setName(String name) this . 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 ;pub

3、lic String getSex()return sex;public String toString() +sex;return "t" +num+"t" +name+"t" +address2. 菜單類(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 .prin

4、tln( *" );System. out .println(System. out .println( =" );)5System. out .println(System. out .println(System. out .println(System. out .println(System. out .println(System. out .println(H*" 客戶管理系統(tǒng) ");" 【 1 】增加 "); "【2】刪除 ");" 【 3 】修改 "); " 【 4 】

5、查詢 ");" 【 5 】瀏覽 ");" 【 6 】退出 ");System.out .println(H*);System. out .print(" 請(qǐng)選擇操作: ");return input .nextInt();public int subMenu() System. out .println( "t 【查詢客戶】 ");System. out .println(System. out .println(System. out .println(System. out .println(Syst

6、em. out .println(retur nin put .n ext lnt()"t1按客戶編號(hào)查詢");"t2按客戶查詢");"t3按地址查詢");"t4退出");"t請(qǐng)選擇查詢編號(hào)");3. 實(shí)際操作類class FileOperatepackage客戶管理系統(tǒng); import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader

7、;import java.ioOException;import java.io.PrintWriter;import java.util.ArrayList;import java.util.List;import java.util.Scan public class FileOperate private static String INFO="D:/info.dat" ;File file = new File( INFO);Scanner input =new Scanner(System. in ); public FileOperate() if (! fil

8、e .exists() try file .createNewFile(); catch (IOException e) e.printStackTrace();public List<Person> getList()throwsNumberFormatException,IOExceptionBufferedReader br =new BufferedReader(newFileReader( file );String msg=null ;List<Person> list = new ArrayList<Person>();while ( msg

9、= br .readLine()!= null ) String arr = msg.split( "t" );int num=Integer. parseInt ( arr 0);String name = arr 1;String address =arr 2;String sex =arr 3;Person person = new Person( num, name, address , sex);list .add( person ); br .close(); return listprivate void savelist(List<Person>

10、 list ) throws FileNotFoundExceptionPrintWriterpw=new PrintWriter(new File( INFO);for (Person c: list ) pw.format( "%dt %st %st %strn" , c.getNum(), c.getName(), c .getAddress(), c .getSex( );pw.close();public int getper( int num) throwsNumberFormatException,IOExceptionList<Person> l

11、ist =getList();for ( int i =0; i <list .size(); i +) Person per =list .get( i );if ( num=per .getNum() return i ;return -1;/ 增加public void insert() throwsNumberFormatException,IOExceptionSystem. out .println( " 請(qǐng)輸入編號(hào): ");intnum=input .nextInt();intindex =getper( num);if( index !=-1) Sys

12、tem. out .println(I!此編號(hào)已存在!");else 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();Person person =newPerson( num, name, address , sex );

13、List<Person> list =getList(); list .add( person ); savelist( list );System. out .println( " 新增成功! ");/ 刪除public void delete() throws NumberFormatException,IOExceptionSystem. out .println( " 請(qǐng)輸入要?jiǎng)h除的編號(hào): "); int num=input .nextInt();List<Person> list =getList();boolean f

14、lag =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/N? " );String answer =input .next();if ("Y" .equalsIgnoreCase( answer ) list .remove( i );savelist( lis

15、t );System. out .println( " 刪除成功 !" );flag =true ;break ;if (! flag ) System. out .println( " 該客戶不存在! ");/ 修改public void update() throwsNumberFormatException,IOExceptionshoAll();System. out .println(" 請(qǐng)輸入編號(hào): n" );int num=input .nextInt();int Id =getper( num);if ( Id !=-

16、1) System. out .println( String name=input System. out .println( String System." 請(qǐng)輸入 :" ); .next();" 請(qǐng)輸入地址 :" );address =input .next(); out .println("請(qǐng)輸入性別 :" )String sex =input .next();List<Person> list =getList();Person per =list .get( Id ); per .setName( name);

17、per .setAddress( address ); per .setSex( sex);showTitle();System. out .println( per);savelist( list );System. out .println( " 修改成功! ");" 編號(hào)不存在! ");else System. out .println(/ 查詢public void search() throwsNumberFormatException,IOExceptionboolean flag =true ; List<Person> lis

18、t =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 .print( "t 請(qǐng)輸入地址: &

19、quot;); findAddress( input .next();break ;case 4: flag =quit(); break ;else System. out .println( " 無任何信息! "); / 按編號(hào)查詢public void findId( int num) throwsNumberFormatException,IOExceptionList<Person> list =getList();boolean flag =falsefor ( inti =0; i <list .size(); i +) Personper

20、= list .get( i );學(xué)習(xí)文檔 僅供參考if ( num=per .getNum() showTitle();System. out .println( per ); flag =true ; break ;if (! flag ) System. out .println( "t 該客戶不存在! ");/ 按查詢public void findName(String name) throwsNumberFormatException,IOExceptionList<Person> list =getList();boolean flag =fals

21、e ;for ( int i =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 該客戶不存在! ");/ 按地址查找public void findAddress(String address )NumberFormatException,IOExce

22、ptionList<Person> list =getList();boolean 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 該客戶不存在!throws);/ 退出查詢public

23、boolean quit() System. out .println( "是否確定退出 Y/N? " ); if ( "Y" .equalsIgnoreCase( input .next() System.out .println(" 退出成功! "returnfalse ;else returntrue ;/ 瀏覽public void shoAll()throwsNumberFormatException,IOExceptionList<Person> list =getList();if ( list .size()!=0) showTitle();for (Person person : list ) System. out .println( person .toString(); else System. out .println( "

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝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ù)覽,若沒有圖紙預(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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論