![計算機科學與技術13-3班實驗二_第1頁](http://file4.renrendoc.com/view/770e0a17703011bd261478f8e1cc4443/770e0a17703011bd261478f8e1cc44431.gif)
![計算機科學與技術13-3班實驗二_第2頁](http://file4.renrendoc.com/view/770e0a17703011bd261478f8e1cc4443/770e0a17703011bd261478f8e1cc44432.gif)
![計算機科學與技術13-3班實驗二_第3頁](http://file4.renrendoc.com/view/770e0a17703011bd261478f8e1cc4443/770e0a17703011bd261478f8e1cc44433.gif)
![計算機科學與技術13-3班實驗二_第4頁](http://file4.renrendoc.com/view/770e0a17703011bd261478f8e1cc4443/770e0a17703011bd261478f8e1cc44434.gif)
![計算機科學與技術13-3班實驗二_第5頁](http://file4.renrendoc.com/view/770e0a17703011bd261478f8e1cc4443/770e0a17703011bd261478f8e1cc44435.gif)
版權說明:本文檔由用戶提供并上傳,收益歸屬內(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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 我的拿手好戲彈鋼琴作文
- 2025年食品安全管理師理論考試復習題庫(含答案)
- 2025年江西楓林涉外經(jīng)貿(mào)職業(yè)學院高職單招職業(yè)適應性測試近5年常考版參考題庫含答案解析
- 2025年江蘇商貿(mào)職業(yè)學院高職單招語文2018-2024歷年參考題庫頻考點含答案解析
- 《稅收管理業(yè)務指導》課件
- 專題04:人稱選用(練習)
- 食品工廠衛(wèi)生作業(yè)內(nèi)容
- 蔬菜基地租賃承包合同范本
- 物業(yè)招標合同書
- 建筑消防系統(tǒng)技術服務合同
- 2025年華僑港澳臺學生聯(lián)招考試英語試卷試題(含答案詳解)
- 2024-2025學年北京石景山區(qū)九年級初三(上)期末語文試卷(含答案)
- 第一章 整式的乘除 單元測試(含答案) 2024-2025學年北師大版數(shù)學七年級下冊
- JD37-009-2024 山東省存量更新片區(qū)城市設計編制技術導則
- 中國高血壓防治指南(2024年修訂版)
- 北京市海淀區(qū)重點中學2025屆高考數(shù)學押題試卷含解析
- GB/Z 44765.3-2024用戶端能源管理系統(tǒng)和電網(wǎng)側管理系統(tǒng)間的接口第3部分:架構
- 《春酒》琦君完整版
- 北師大版(2024新版)七年級上冊數(shù)學第四章《基本平面圖形》測試卷(含答案解析)
- 湖南省邵陽市武岡市2024屆高三上學期期中考試地理含答案解析
- 春節(jié)后復工安全教育培訓考試試題及答案
評論
0/150
提交評論