




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、package exercise; import java.io.*; class stafflnfo / 職工類 publicStringn ame publicStringnum publicStringsex; publicStringage; publicStringrecord ; publicStringpositi on; publicStringwanges; publicStringtel ; publicStringaddr; public class StaffInfomation/ 實(shí)現(xiàn)部分 public static void main( final String a
2、rgs) throws IOException staffI nfo staffO ne=new staffI nfo100; for (int j=O;j1OO;j+) staffO nej =new staffI nfo(); final ways staffTwo= new ways(); staffTwo.caida n( staffO ne); staffTwo.creat(staffO ne); staffTwo.output(staffO ne); staffTwo.search(staffO ne); staffTwo.delete(staffO ne); class ways
3、 /方法類,主要實(shí)現(xiàn)職工信息的建立,顯示,查找,刪除,信息的保存與讀取; 這個(gè)類是整個(gè)程序的操作類。 public Stri ng recordkey ; public int i =0; /i用來存放職工的人數(shù) public Stri ng file name =I nfomatio n. txt BufferedReaderbuf =new BufferedReader( new In putStreamReader(System.in); void caidan(staffInfo staffOne)throws IOException final BufferedReader buf=
4、 newBufferedReader( newInputStreamReader(System.in ); /此處是JAVA語言中輸入數(shù)據(jù)的基本格式,功能有如C中的scanf函數(shù) int choice; II ! 職工管理系統(tǒng)主菜單界面 do System.out .pri ntl n( 1 ); System.out .pri ntl n( choice=ln teger. switch (choice) case 1:creat(staffO ne); case 2:output(staffO ne); case 3:search(staffO ne); case 4:delete(sta
5、ffO ne); case 5:read(staffO ne); case 6:save(staffO ne); !); Syste m. out.println( ” | 1 ) System. J out .pri ntln( 1 1. .輸 入職工信息 1); System. out.pri ntln( 1 2. 預(yù)覽職工信息 1); System. out.pri ntln( 1 3. 查找職工信息 1); System. out.pri ntln( 1 4. 刪除職工信息 1); System. out.pri ntln( 1 5. 讀取已 存數(shù)據(jù) 1); System. out .
6、pri ntln( 1 6. 安全退出系統(tǒng) 1); Syste m. i ) out.pri ntln( 1 ) System. J out.pri nt( 請(qǐng)輸入您需要的功能代號(hào) (1-6):); parseInt (buf.readLine(); break ; break ; break ; break ; break ; break ; while (choice!=0); void creat(staffI nfo staffO ne) throws IOExcepti on finalBufferedReader InputStreamReader(System.in ); Sys
7、tem. out .print(請(qǐng)輸入職工信息(以 System. out .print(姓名:); staffOne i . name=buf.readLine();/ buf= new 0結(jié)束)n); 用數(shù)組 staffOnei BufferedReader( new 來暫存職工的相關(guān)信息 while (staffOne i . namecompareTo( 0 )!=0) / 用 compareTo方法確定判定是否應(yīng)該 寫入新信息 System. out .print(工號(hào):”); staffOne i . nun=buf.readLine(); System. out .print(性
8、別:); staffOne i . sex=buf.readLine(); System. out .print(年齡:); staffOne i . age=buf.readLine(); System. out .print(學(xué)歷:); staffOne i . record =buf.readLine(); System. out .print(職位:); staffOne i . position =buf.readLine(); System. out .print(工資:); staffOne i . wanges=buf.readLine(); System. out .prin
9、t(電話:”); staffOne i . tel =buf.readLine(); System. out .print(住址:); staffOne i . addr=buf.readLine(); i +; System. out .println(”請(qǐng)輸入下一個(gè)職工信息:); staffOne i . name=buf.readLine(); void output(staffInfo staffOne)throws IOException / 這里是實(shí)現(xiàn)輸出(預(yù)覽) 職工信息” output的模塊 for (int j=0;j i ;j+) if (i !=0) System. ou
10、t .println( ” ); System. out .println(* 工信息表*); System. out .println( ” ); System. out .println( ”姓名t工號(hào)tt 性別t年齡t學(xué)歷t職位tt 工 t電話號(hào)碼tt 住址); System. out .println( ” System, out .print(staffOt +staffOnej. num+t +staffOnej. sex+t +staffO nej. age+t +staffO nej. record +t +staffO nej. positi on +tt +
11、staf fOnej. wanges+t +staffOnej.tel +t +staffOnej. addr+n); System. out .println( ” ); else System. out.println(沒有職工信息!”); void search(stafflnfo staffOne)throws IOException final BufferedReader buf= newBufferedReader( newInputStreamReader(System.in ); System. out .print(請(qǐng)輸入您要查找的職工工號(hào):”); recordkey =b
12、uf.readL in e(); boolean flg= true ; for (int j=O;j i ;j+) if (recordkey .equals(staffOnej. num) /equals 是字符串比較函數(shù)相等返回 true System. out.println(” ); System. out .println(”*職工信息表 * ); System. out.println(” ); System. out.println(”姓名t工號(hào)tt 性別t年齡t學(xué)歷t職位tt 工資t 電話號(hào)碼tt 住址); System. out.println(” ); System. o
13、ut.println(staffOt +staffOnej.num+t +staffOnej. sex+ t +staffO nej.age+t +staffO nej. record +t +staffO nej.positio n +tt +st affOnej. wanges+t +staffOnej. tel +t +staffOnej. addr+n); flg= false ; if (flg) System. out .println(” 對(duì)不起,查無此人!”); void delete(stafflnfo staffOne)throws lOException
14、final BufferedReader buf= newBufferedReader( newInputStreamReader(System.in ); System. out .print(請(qǐng)輸入您要?jiǎng)h除的職工工號(hào):); recordkey =buf.readL in e(); boolean flg= true ; for (int j=O;j i ;j+) System. out .println(輸入的工號(hào)為:+recordkey ); if (recordkey .equals(staffOnej. nun) for (int k=j;k= i -1;k+)/禾U用順序表的刪除算
15、法,刪除值之后,再把后面 的值往前移位,從而實(shí)現(xiàn)刪除 staffO nek. n ame=staffO nek+1. n ame; staffO nek. n um=staffO nek+1. num; staffO nek. sex =staffO nek+1. sex; staffO nek. age=staffO nek+1. age ; staffO nek. record =staffO nek+1 record ; staffO nek. positi on =staffO nek+1.positi on staffO nek. wan ges=staffO nek+1 wange
16、s; staffO nek. tel =staffO nek+1. tel ; staffO nek. addr =staffO nek+1. addr ; i -; /職工人數(shù)減一 flg= false ; if (flg) System. out .println(” 對(duì)不起,查無此人!?!?; else System. out .println(” 已經(jīng)刪除該職工信息!。); void save(stafflnfo staffOne)throws lOException / 數(shù)據(jù)的保存模塊,把輸入的職 工信息保存到相應(yīng)的文件里。 int k; final FileWriter fw= n
17、ew FileWriter( file name ); / 調(diào)用構(gòu)造函數(shù) FileWriter ()創(chuàng) 建FileWriter 類的對(duì)象。 fw.write( i +n ); /把職工的人數(shù)保存到文件中以便下次讀取時(shí)使用 for ( k=0;k i ;k+) /每個(gè)職工有9個(gè)信息字段,下面就是這9個(gè)信息段。 fw.write( staffO nek. fw.write( staffO nek. fw.write( staffO nek. fw.write( staffO nek. fw.write( staffO nek. fw.write( staffO nek. fw.write( sta
18、ffO nek. fw.write( staffO nek. fw.write( staffO nek. namen); nun+n); sex+n); age+n); record +n); position +n); wanges+n); tel +n); addr+n); staffO nej. staffO nej. staffO nej. staffO nej. staffO nej. staffO nej. staffO nej. staffO nej. staffO nej. fw.close(); System.out.pri ntl n(”系統(tǒng)已經(jīng)安全退出!感謝您的使用!”); System. exit (0); throws IOException void read(stafflnfo staffOne) final FileReader fr= new FileReader( file name ); final BufferedReader bfr= new BufferedReader(fr); if ( recordkey =bfr.readLine()!=null ) i =lnteger. parseInt (reco
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 荷斯坦牛能量代謝指標(biāo)遺傳參數(shù)估計(jì)及全基因組關(guān)聯(lián)分析
- 熱處理對(duì)AlCrCuFe2NiTix系高熵堆焊合金組織和性能的影響
- 皖東X村村落空心化背景下自然神靈崇拜變遷研究
- 初中家長(zhǎng)會(huì)課件教學(xué)
- 初中家長(zhǎng)會(huì)家長(zhǎng)課件
- 個(gè)案護(hù)理方案
- 交通運(yùn)輸行業(yè)交通信息化安全人才需求與培養(yǎng)策略報(bào)告
- 交通運(yùn)輸行業(yè)節(jié)能減排技術(shù)創(chuàng)新與市場(chǎng)需求研究報(bào)告
- 2025百貨店門面租賃合同范本:多元化租賃合作協(xié)議
- 2025版班輪運(yùn)輸合同標(biāo)準(zhǔn)文本(貨物保險(xiǎn)附加)
- 五升六數(shù)學(xué)暑假作業(yè)每日一練打印練習(xí)
- 2025年入黨考試題及答案
- 低空經(jīng)濟(jì)專題系列報(bào)告四:無人機(jī)與低空物流:擁抱無人物流時(shí)代
- 新校區(qū)搬遷活動(dòng)方案
- 2025SYB創(chuàng)業(yè)考試題庫(kù)及答案
- 新鄉(xiāng)市縣以下事業(yè)單位聯(lián)考招聘筆試真題2024
- 折讓證明模板
- 培智學(xué)生XXX個(gè)別化教育手冊(cè)
- AWG,SWG,BWG線規(guī)規(guī)格對(duì)照表
- 《房屋面積測(cè)算技術(shù)規(guī)程》DGJ32TJ131-2022
- (整理)小學(xué)數(shù)獨(dú)游戲校本課程教材.
評(píng)論
0/150
提交評(píng)論