




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、Java 技術(shù)實(shí)驗(yàn)實(shí)驗(yàn)( 二 )(紅色部分,請大家需要根據(jù)具體實(shí)驗(yàn)內(nèi)容認(rèn)真思考、替換):2014年 12月 20日學(xué)院計(jì)算機(jī)與信息學(xué)院專業(yè)班級計(jì)算機(jī)科學(xué)與技術(shù) 13-3 班學(xué)號2013211682實(shí)驗(yàn)名稱貨物進(jìn)銷管理系統(tǒng)指導(dǎo)教師老師教師評語教師簽名:年月日一、實(shí)驗(yàn)?zāi)康恼莆?Java 中文件的讀寫操作。學(xué)會使用 Java 提供的實(shí)用類(Vector, ArrayList)來完成特定的功能。 3掌握字符串類(String, StringBuffer)的使用。4掌握用面象的方法分析和解決復(fù)雜問題二、實(shí)驗(yàn)原理使用 java 中的文件讀寫功能完成對文件的操作。將不同的項(xiàng)目寫一個(gè)類,源文件的內(nèi)容后實(shí)例化對
2、象進(jìn)行操作。將操作完的對象保存在 vector 里以便輸出和排序。利用 collections.sort()方法對 vector 進(jìn)行排序三、使用硬件、環(huán)境筆記本一臺 cpu 頻率為 2.2Ghz,內(nèi)存為 8G,系統(tǒng)為 win8.1使用 eclipse四、實(shí)驗(yàn)過程、步驟及原始(算法、原程序、,分析等)import java.io.*;import java.util.*;class Inventory implementsComparable /Inventory 類實(shí)現(xiàn) Comparable 接口String item;/方便用 collections.sort 方法排序egerty;/該類
3、從 Inventory.dat 中的內(nèi)容Stringr;String descriptions;eger getty()returnty;eger getItem()returnegarse(item);publiccompareTo(Inventory a)returnthis.getItem().compareTo(a.getItem();class Tranions implements Comparable/該類Tranions.dat 文件中的內(nèi)容String action;實(shí)現(xiàn)parable 接口以便排序String item;egerty;Stringcustom;Stringd
4、escriptions;Stringr;publiccompareTo(Tranions a)returnpareTo(a.ty);class Error/Error 條目的內(nèi)容Stringcustom;Stringitem;ty;class Ship/ship條目的內(nèi)容Stringcustom;Stringitem;ty;public class Managementpublic sic void main(String args)throws IOExceptionFileError=new File(Errors.dat);FileInventory=new File(Inventory
5、.dat);/的源和寫入的目的地FileTranions=new File(Tranions.dat);FileShip=new File(Ship.dat);FileNewInventory=new File(NewInventory.dat);FileWriterfError=new FileWriter(Error);FileReaderfInventory=new FileReader(Inventory);FileReaderfTranions=new FileReader(Tranions);FileWriterfShip=new FileWriter(Ship);FileWrit
6、erfNewInventory=new FileWriter(NewInventory);BufferedWriterbfError=new BufferedWriter(fError);/buffered 類以便調(diào)用readline 方法BufferedReaderbfInventory=new BufferedReader(fInventory);BufferedReaderbfTranions=new BufferedReader(fTranions);BufferedWriterbfShip=new BufferedWriter(fShip);BufferedWriterbfNewIn
7、ventory=new BufferedWriter(fNewInventory);Vector Ivector= new Vector();/一個(gè)Vector 存放 Inventory 對象String Istr;String Istr1=new String4;while(Istr=bfInventory.readLine()!=null)/將的內(nèi)容放入Inventory 對象Istr1=Istr.split(t);/并將該對象放入 VectorInventory i=new Inventory();i.item=Istr10;i.ty=egarse(Istr11);i.r=Istr12;
8、i.descriptions=Istr13;Ivector.add(i);Vector TvectorVector(); /四個(gè)Vector 存放 Tranions 的四種處理方式VectorTvectorR=newVector();VectorTvectorA=newVector();VectorTvectorD=newVector();StringTstr;StringTstr1=new String 4;while(Tstr=bfTranions.readLine()!=null)/Tranions 并按照處理方式Tstr1=Tstr.split(t);/不同放入的四個(gè) VectorTr
9、anions t=new Tranions();switch(Tstr10)caseO:t.item=Tstr11;t.ty=egarse(Tstr12);t.custom=Tstr13;TvectorO.add(t);break;caseR:t.item=Tstr11;t.ty=egarse(Tstr12);TvectorR.add(t);break;caseD:t.item=Tstr11;TvectorD.add(t);break;caseA:t.item=Tstr11;t.r=Tstr12;t.descriptions=Tstr13;TvectorA.add(t);break;Vecto
10、r Evector=new Vector(); /存放 Error 類對象和Ship類對象的 VectorVector Svector=new Vector();Collections.sort(TvectorO); /對執(zhí)行 O 操作的 Tranions 排序,使數(shù)量最小的在最上/避免出貨數(shù)量多于存貨時(shí)再將數(shù)量少的先出的動作for(r=0;rTvectorR.size();r+)/對 R 的處理for(n=0;nIvector.size();n+)if(Ivectet(n).item.equals(TvectorR.get(r).item)Ivectet(n).ty=Ivectet(n).t
11、y+TvectorR.get(r).ty;for(a=0;aTvectorA.size();a+)/對 A 的處理Inventory Inv= new Inventory();Inv.item=TvectorA.get(a).item;Inv.descriptions=TvectorA.get(a).descriptions;Inv.r=TvectorA.get(a).r;Inv.ty=0;Ivector.add(Inv);for(o=0;oTvectorO.size();o+)/對 O 的處理for(j=0;jIvector.size();j+)if(Ivectet(j).item.equa
12、ls(TvectorO.get(o).item)if(Ivectet(j).tyTvectorO.get(o).ty)Error error= new Error();error.custom=TvectorO.get(o).custom;error.item=TvectorO.get(o).item;error.ty=TvectorO.get(o).ty;Evector.add(error);elseIvectet(j).ty=Ivectet(j).ty-TvectorO.get(o).ty;Shipship=new Ship();ship.custom=TvectorO.get(o).cu
13、stom;ship.item=TvectorO.get(o).item;ship.ty=TvectorO.get(o).ty;Svector.add(ship);for(d=0;dTvectorD.size();d+)/對 D 的處理for(m=0;mIvector.size();m+)if(Ivectet(m).item.equals(TvectorD.get(d).item)if(Ivectet(m).ty!=0)Error errorD= newError();errorD.item=Ivectet(m).item;errorD.ty=Ivectet(m).ty;errorD.custo
14、m=0;elseIvector.remove(m);for(e=0;eEvector.size();e+) /將結(jié)果寫入相應(yīng)的文件并關(guān)閉流bfError.write(Evectet(e).custom +t+Evectet(e).item+t+Evectet(e).ty);bfError.newLine();bfError.close();Collections.sort(Ivector);for(ne=0;neIvector.size();ne+)bfNewInventory.write(Ivectet(ne).item+t+Ivectet(ne).ty+t+Ivectet(ne).r+t+
15、Ivectet(ne).descriptions);bfNewInventory.newLine();bfNewInventory.close();for(s=0;sSvector.size();s+)bfShip.write(Svectet(s).custom+t+Svectet(s).item+t+Svectet(s).ty);bfShip.newLine();bfShip.close();bfInventory.close();bfTranions.close();從目標(biāo)文件字符串,根據(jù)第一個(gè)字母的不同,使用不同的方法操作文件,這里要提一點(diǎn),在處理出貨時(shí),由于存貨不足需要先出貨數(shù)量少的,可以先排序在處理,這樣可以免去一些麻煩。實(shí)驗(yàn)結(jié)果為:五、實(shí)驗(yàn)結(jié)論、分析、思考題與心得體會通過本次實(shí)驗(yàn),我有以下幾方面的收
溫馨提示
- 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)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- JJF 2259-2025磁強(qiáng)計(jì)校驗(yàn)裝置校準(zhǔn)規(guī)范
- 2025年廣州貨運(yùn)從業(yè)資格證網(wǎng)上考試題庫及答案
- 利用志愿服務(wù)活動推動勞動教育的實(shí)踐研究
- 人力資源管理招聘與選拔實(shí)務(wù)測試題
- ××超市打印設(shè)備辦法
- ××中學(xué)訴訟管理制度
- 2025年運(yùn)動場館燈具項(xiàng)目規(guī)劃申請報(bào)告
- 2025年公路養(yǎng)護(hù)檢測設(shè)備項(xiàng)目申請報(bào)告
- 2025年觀光型酒店項(xiàng)目提案報(bào)告模板
- 醫(yī)學(xué)微生物學(xué)案例分析題集
- GA 1800.5-2021電力系統(tǒng)治安反恐防范要求第5部分:太陽能發(fā)電企業(yè)
- 膿毒癥指南解讀2021完整版課件
- 起重機(jī)械制動器和制動輪的檢查規(guī)定
- 醫(yī)院感染質(zhì)量檢查反饋記錄登記
- 乳糜漏的護(hù)理培訓(xùn)課件
- 站區(qū)道路施工監(jiān)理平行檢查記錄
- 兒童口腔科接診基本流程綱要
- 公司工作流程圖
- GB∕T 34876-2017 真空技術(shù) 真空計(jì) 與標(biāo)準(zhǔn)真空計(jì)直接比較校準(zhǔn)結(jié)果的不確定度評定
- (完整版)管理經(jīng)濟(jì)學(xué)題庫
- 車工技師論文 細(xì)長軸的加工技術(shù)方法
評論
0/150
提交評論