




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Java 技术实验实验( 二 )(红色部分,请大家需要根据具体实验内容认真思考、替换):2014年 12月 20日学院计算机与信息学院专业班级计算机科学与技术 13-3 班学号2013211682实验名称货物进销管理系统指导教师老师教师评语教师签名:年月日一、实验目的掌握 Java 中文件的读写操作。学会使用 Java 提供的实用类(Vector, ArrayList)来完成特定的功能。 3掌握字符串类(String, StringBuffer)的使用。4掌握用面象的方法分析和解决复杂问题二、实验原理使用 java 中的文件读写功能完成对文件的操作。将不同的项目写一个类,源文件的内容后实例化对
2、象进行操作。将操作完的对象保存在 vector 里以便输出和排序。利用 collections.sort()方法对 vector 进行排序三、使用硬件、环境笔记本一台 cpu 频率为 2.2Ghz,内存为 8G,系统为 win8.1使用 eclipse四、实验过程、步骤及原始(算法、原程序、,分析等)import java.io.*;import java.util.*;class Inventory implementsComparable /Inventory 类实现 Comparable 接口String item;/方便用 collections.sort 方法排序egerty;/该类
3、从 Inventory.dat 中的内容Stringr;String descriptions;eger getty()returnty;eger getItem()returnegarse(item);publiccompareTo(Inventory a)returnthis.getItem().compareTo(a.getItem();class Tranions implements Comparable/该类Tranions.dat 文件中的内容String action;实现parable 接口以便排序String item;egerty;Stringcustom;Stringd
4、escriptions;Stringr;publiccompareTo(Tranions a)returnpareTo(a.ty);class Error/Error 条目的内容Stringcustom;Stringitem;ty;class Ship/ship条目的内容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 类以便调用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)/将的内容放入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); /对执行 O 操作的 Tranions 排序,使数量最小的在最上/避免出货数量多于存货时再将数量少的先出的动作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();从目标文件字符串,根据第一个字母的不同,使用不同的方法操作文件,这里要提一点,在处理出货时,由于存货不足需要先出货数量少的,可以先排序在处理,这样可以免去一些麻烦。实验结果为:五、实验结论、分析、思考题与心得体会通过本次实验,我有以下几方面的收
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 二级Web考试核心竞争力试题
- 开门红开启新一年的奋斗序幕
- (三模)九江市2025年高三第三次高考模拟考试英语试卷(含答案)
- 经济放水措施方案(3篇)
- 健全就业公共服务体系的策略及实施路径
- 城市轨道交通安全管理题库及答案
- 高等教育改革与产教融合发展的策略及实施路径
- 计算机四级嵌入式架构设计试题及答案
- 传统节日的价值与现代变革
- 逻辑应用与财务分析考量试题及答案
- 3D打印建筑材料
- 病理检验技术练习试题附答案
- 监理检测和试验仪器设备一览表
- 小型轧钢机结构设计
- 房屋拆除工程专项施工方案
- 像冠军一样教学读后感3实用
- 电力安全生产事故调查规程
- GB/T 18781-2023珍珠分级
- GA/T 544-2021多道心理测试系统通用技术规范
- 《法理学》考试笔记与重点
- DB44!T+2419-2023全生晒柑普茶生产技术规程
评论
0/150
提交评论