Java实现商品入库.docx
Id(), goods3); map.put(goods4.getId(), goods4); map.put(goods5.getId(), goods5); } public static void main(String[] args) { get(); System.out.println("请输入商品编号进行查找:"); int id = in.nextInt(); Goods1 find = (Goods1) map.get(id); if (find != null) { System.out.println("找到的商品为:" + find.getName()); System.out.println("单价为:" + find.getPrice()); System.out.println("库存为:" + find.getBalance()); } else { System.out.println("未找到该商品"); } System.out.println("请输入要入库的商品编号:"); id = in.nextInt(); Goods1 goods = new Goods1(id, "", 0.0, "", 0); System.out.println("请输入商品名称:"); goods.setName(in.next()); System.out.println("请输入商品单价:"); goods.setPrice(in.nextDouble()); System.out.println("请输入商品单位:"); goods.setUom(in.next()); System.out.println("请输入入库数量:"); goods.setBalance(in.nextInt()); map.put(goods.getId(), goods); System.out.println("入库成功!"); showAll(); } public static void showAll() { Set set = map.entrySet(); Iterator it = set.iterator(); System.out.println("所有商品信息如下:"); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); Goods1 goods = (Goods1) entry.getValue(); System.out.println("编号:" + entry.getKey() + ",名称:" + goods.getName() + ",单价:" + goods.getPrice() + ",单位:" + goods.getUom() + ",库存:" + goods.getBalance()); } System.out.println("所有商品的总库存数为:" + totalStock() + "件"); System.out.println("库存商品总金额为:" + totalAmount() + "元"); } public static int totalStock() { int sum = 0; for (Object obj : map.values()) { Goods1 goods = (Goods1) obj; sum += goods.getBalance(); } return sum; } public static double totalAmount() { double sum = 0; for (Object obj : map.values()) { Goods1 goods = (Goods1) obj; sum += goods.getBalance() * goods
- 粉丝: 7153
- 资源: 46
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助