当前位置: 首页 > news >正文

安徽省建设安全质量协会网站单位建设网站硬件

安徽省建设安全质量协会网站,单位建设网站硬件,汕头网站制作找哪里,网页界面设计作品实验二货物进销管理系统一#xff0e;实验目的1#xff0e;掌握Java中文件的读写操作。2#xff0e;学会使用Java提供的实用类(Vector, ArrayList)来完成特定的功能。3#xff0e;掌握字符串类(String, StringBuffer)的使用。4#xff0e;掌握用面向对象的方法分析和解决复…实验二货物进销管理系统一实验目的1掌握Java中文件的读写操作。2学会使用Java提供的实用类(Vector, ArrayList)来完成特定的功能。3掌握字符串类(String, StringBuffer)的使用。4掌握用面向对象的方法分析和解决复杂问题。二实验内容编写一个Inventory.java完成以下功能(没有学过Java文件处理之前各位同学可以使用硬编码将数据放进两个Vector变量里。等学过Java文件处理之后再补充数据文件读取部分)1程序首先打开并读取Inventory.txt中记录的所有库存记录然后读取Transactions.txt处理这个文件中包含的事务记录发货记录到Shipping.txt并记录错误信息到Errors.txt中。最后更新库存到另外一个文件NewInventory.txt中。2文件Inventory.txt和NewInventory.txt的每行包含一个存货记录每条记录包含下面一些字段息这些字段之间用一个tab分开(见后面的文件格式)字段格式和含义Item number字符串型货物编号Quantity整型货物数量Supplier字符串型供应商编号Description字符串型货物描述3字段Items按照从小到大的顺序写入文件的。注意Item号不必连续如Item号为752的后面可能是800。4文件Transactions.txt包含几个不同的处理记录(每行一条记录)。每条记录前面以一个大写字母开头表示这条记录是什么类型的事务。在不同的大写字母后面是不同的信息格式。所有的字段也是以tab键分开的(见Transactions.txt文件格式)。5以O开头的事务表示这是一个发货订单即某一种货物应该发给特定的客户。Item number和Quantity的格式如上面表格定义。Custom编号和上面的Supplier编号一致。处理一条定单记录(以O开头的事务)意味着从减少库存记录中相应货物的数量(减少的数量发货单中的数量)记录发货信息到Shipping.txt中。注意Inventory.txt中的quantity不应该小于0如果对于某一种货物库存的数量小于发货单的数量的话系统应该停止处理发货单并记录出错信息到Errors.txt。如果对于某一种货物有多个发货单而且库存总量小于这些发货单的总和的话系统应该按照发货单中的数量从小到大的有限原则满足客户。也就是说对于某一种货物如果一个数量Quantity少的发货单没有处理之前数量Quantity多的发货单永远不会被处理。(这种处理原则不受发货单记录在Transactions.txt的先后顺序影响)6以R开头的事务表示这是一个到货单记录在R后面是Item number和它的数量Quanlity。处理一条到货单意味着增加库存中相应货物的数量(增加的数量到货单中的数量)。注意如果在Transactions.txt文件中到货单出现在发货单之后到货单中的货物数量可以用来填补发货单中的数量(可以理解成在Transactions.txt中优先处理到货单)。7以A开头的事务表示向库存中增加一种新的货物(即这种货物以前库存中没有)在A后面是Item number供应商supplier以及货物的描述description。处理一个新增货物记录意味着向库存中增加一个数量Quantity为0的新的Item。你可以假设在一个Transactions.txt中新增货物记录总是出现在第一个到货单之前。8以D开头的事务表示从库存中删除一种货物在D后面是Item号。删除操作总是在所有的事物处理之后才被处理以保证对于可能出现的同一种货物的发货单的操作能在删除之前被正确处理。如果要删除的某种货物的库存量Quantity不为0的话系统应该向Errors.txt记录出错信息。9文件Shipping.txt中的每一行代表给某一客户的发货信息。Shipping.txt中的每一行分别是客户编号、Item号、货物数量它们之间用tab键分隔。如果发货单中有两条客户编号和Item编号一样的记录在Shipping.txt中应该将这两条发货信息合并(即将它们的数量相加)。10Errors.txt文件包含未发送的发货记录和库存量大于0的删除记录。Errors.txt每一行包含Custom编号、Item编号以及发货单上的数量Quantity。对于删除操作Custom编号为0数量Quntity为库存中的Quantity.11实验测试数据:Inventory.txtTransactions.txt提示tab键分隔在字符串处理的时候采用’\t’进行处理三思考题1. 对整个实验进行总结写出实验心得。import javafx.util.Pair;import java.io.*;import java.util.*;public class Inventory {public String itemNumber;public int quantity;public String supplier;public String description;public static void main(String[] args) throws IOException {String s null;ListinventoryList new ArrayList();MapitemToIndex new HashMap();BufferedReader inventoryReader new BufferedReader(new FileReader(src/Inventory.txt));while((s inventoryReader.readLine()) ! null){String[] split s.split(\t);inventoryList.add(new Inventory(split[0], Integer.parseInt(split[1]), split[2], split[3]));itemToIndex.put(split[0], inventoryList.size() - 1);}inventoryReader.close();List transactionsList new ArrayList();for(int i 0; i 4; i){ transactionsList.add(new ArrayList()); }BufferedReader transactionsReader new BufferedReader(new FileReader(src/Transactions.txt));while((s transactionsReader.readLine()) ! null){switch(s.charAt(0)){case O:transactionsList.get(0).add(s);break;case R:transactionsList.get(1).add(s);break;case A:transactionsList.get(2).add(s);break;case D:transactionsList.get(3).add(s);break;default:break;}}transactionsReader.close();for(String temp : transactionsList.get(2)){String[] split temp.split(\t);inventoryList.add(new Inventory(split[1], 0, split[2], split[3]));itemToIndex.put(split[1], inventoryList.size() - 1);}for(String temp : transactionsList.get(1)){String[] split temp.split(\t);inventoryList.get(itemToIndex.get(split[1])).quantity Integer.parseInt(split[2]);}Collections.sort(transactionsList.get(0), new SortByString());Map shippingList new HashMap();BufferedWriter errorWriter new BufferedWriter(new FileWriter(src/Error.txt));for(String temp : transactionsList.get(0)){String[] split temp.split(\t);if(Integer.parseInt(split[2]) inventoryList.get(itemToIndex.get(split[1])).quantity){inventoryList.get(itemToIndex.get(split[1])).quantity - Integer.parseInt(split[2]);if(shippingList.containsKey(split[3]) shippingList.get(split[3]).getKey() split[1]){shippingList.put(split[3], new Pair(split[1],Integer.parseInt(split[2]) shippingList.get(split[3]).getValue()));}else{shippingList.put(split[3], new Pair(split[1], Integer.parseInt(split[2])));}}else{errorWriter.write(split[3] \t split[1] \t split[2]);errorWriter.newLine();}}for(String temp : transactionsList.get(3)){String[] split temp.split(\t);if(inventoryList.get(itemToIndex.get(split[1])).quantity 0){errorWriter.write(0 \t itemToIndex.get(split[1]) \t inventoryList.get(itemToIndex.get(split[1])).quantity);errorWriter.newLine();}inventoryList.remove((int)itemToIndex.get(split[1]));}errorWriter.close();BufferedWriter shippingWriter new BufferedWriter(new FileWriter(src/Shipping.txt));for (Map.Entry entry : shippingList.entrySet()) {shippingWriter.write(entry.getKey() \t entry.getValue().getKey() \t entry.getValue().getValue());shippingWriter.newLine();}shippingWriter.close();BufferedWriter newInventoryWriter new BufferedWriter(new FileWriter(src/NewInventory.txt));for(Inventory inventory : inventoryList){newInventoryWriter.write(inventory.itemNumber \t inventory.quantity \t inventory.supplier \t inventory.description);newInventoryWriter.newLine();}newInventoryWriter.close();}public Inventory(String itemNumber, int quantity, String supplier, String description) {this.itemNumber itemNumber;this.quantity quantity;this.supplier supplier;this.description description;}}class SortByString implements Comparator {public int compare(Object o1, Object o2) {String[] s1 ((String)o1).split(\t);String[] s2 ((String)o2).split(\t);return Integer.parseInt(s1[2]) Integer.parseInt(s2[2]) ? 1 : -1;}}//大吉大利今晚AC
http://www.pierceye.com/news/267972/

相关文章:

  • 班级网站主页设计模板购买网站域名空间
  • 做响应式网站最大宽度景观设计公司起名
  • 有小广告的网站适合40岁女人的培训班
  • html5网站建设有什么网站用名字做图片
  • 合肥珍岛公司做网站推广怎么样关键词排名优化如何
  • 做讲课ppt的网站郑州市建设局官方网站
  • 邢台集团网站建设报价免费推广网站有哪些
  • 龙华网站建设营销推广广东东莞区号
  • 徐汇网站开发培训企业建网站报价
  • 专业网站建设公司兴田德润信任高建设高端网站公司哪家好
  • 烟台网站建设优惠臻动传媒做网站怎么挣钱
  • 重庆网站建设mlfartwordpress4 中文
  • 永州建设企业网站阿里云 网站部署
  • 学校做网站难吗创新logo设计
  • 国内用python做的网站如何做网站讯息
  • 的网站开发工具有哪些免费制作永久企业网站
  • 网站举报查询一个网站开发的权限
  • 简约网站程序海南网络广播电视台少儿频道
  • 深圳高端品牌网站设计wordpress 树形主题
  • 怎么自己创建一个网站国外企业网络研究
  • 去百度建网站北京企业网站设计公司
  • mysql 收费 网站建设wordpress主题后台不显示
  • 网站cname解析陕西住房建设厅考试官方网站
  • 网站建设有关书籍设计制作散发寄递
  • 威海建设信息网站织梦网站广告代码如何写
  • 玉林市网站开发公司wordpress tag静态化
  • 广州网站建设建航科技百度域名书写
  • 免费做网站安全吗网站不备案可以访问吗
  • 网上做网站兼职最近10条重大新闻
  • 企业网站制作 徐州政务网站建设要求