計算機科學與技術13-3班實驗二_第1頁
計算機科學與技術13-3班實驗二_第2頁
計算機科學與技術13-3班實驗二_第3頁
計算機科學與技術13-3班實驗二_第4頁
計算機科學與技術13-3班實驗二_第5頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、Java 技術實驗實驗( 二 )(紅色部分,請大家需要根據(jù)具體實驗內(nèi)容認真思考、替換):2014年 12月 20日學院計算機與信息學院專業(yè)班級計算機科學與技術 13-3 班學號2013211682實驗名稱貨物進銷管理系統(tǒng)指導教師老師教師評語教師簽名:年月日一、實驗目的掌握 Java 中文件的讀寫操作。學會使用 Java 提供的實用類(Vector, ArrayList)來完成特定的功能。 3掌握字符串類(String, StringBuffer)的使用。4掌握用面象的方法分析和解決復雜問題二、實驗原理使用 java 中的文件讀寫功能完成對文件的操作。將不同的項目寫一個類,源文件的內(nèi)容后實例化對

2、象進行操作。將操作完的對象保存在 vector 里以便輸出和排序。利用 collections.sort()方法對 vector 進行排序三、使用硬件、環(huán)境筆記本一臺 cpu 頻率為 2.2Ghz,內(nèi)存為 8G,系統(tǒng)為 win8.1使用 eclipse四、實驗過程、步驟及原始(算法、原程序、,分析等)import java.io.*;import java.util.*;class Inventory implementsComparable /Inventory 類實現(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;實現(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();/一個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(); /四個Vector 存放 Tranions 的四種處理方式VectorTvectorR=newVector();VectorTvectorA=newVector();VectorTvectorD=newVector();StringTstr;StringTstr1=new String 4;while(Tstr=bfTranions.readLine()!=null)/Tranions 并按照處理方式Tstr1=Tstr.split(t);/不同放入的四個 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ù)量少的先出的動作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+) /將結果寫入相應的文件并關閉流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();從目標文件字符串,根據(jù)第一個字母的不同,使用不同的方法操作文件,這里要提一點,在處理出貨時,由于存貨不足需要先出貨數(shù)量少的,可以先排序在處理,這樣可以免去一些麻煩。實驗結果為:五、實驗結論、分析、思考題與心得體會通過本次實驗,我有以下幾方面的收

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論