课堂测试重写
public class WarehouseInformation { private String itemno; private String itemname; private String suppliername; private String warehousingtime; private String shipmenttime; private String warehousenumber; private String warehouseplace; private int itemnumber; private int outnumber; public WarehouseInformation(String itemno, String itemname, String suppliername, String warehousingtime, String shipmenttime, String warehousenumber, String warehouseplace, int itemnumber, int outnumber) { super(); this.itemno = itemno; this.itemname = itemname; this.suppliername = suppliername; this.warehousingtime = warehousingtime; this.shipmenttime = shipmenttime; this.warehousenumber = warehousenumber; this.warehouseplace = warehouseplace; this.itemnumber = itemnumber; this.outnumber = outnumber; } public String getItemno() { return itemno; } public void setItemno(String itemno) { this.itemno = itemno; } public String getItemname() { return itemname; } public void setItemname(String itemname) { this.itemname = itemname; } public String getSuppliername() { return suppliername; } public void setSuppliername(String suppliername) { this.suppliername = suppliername; } public String getWarehousingtime() { return warehousingtime; } public void setWarehousingtime(String warehousingtime) { this.warehousingtime = warehousingtime; } public String getShipmenttime() { return shipmenttime; } public void setShipmenttime(String shipmenttime) { this.shipmenttime = shipmenttime; } public String getWarehousenumber() { return warehousenumber; } public void setWarehousenumber(String warehousenumber) { this.warehousenumber = warehousenumber; } public String getWarehouseplace() { return warehouseplace; } public void setWarehouseplace(String warehouseplace) { this.warehouseplace = warehouseplace; } public int getItemnumber() { return itemnumber; } public void setItemnumber(int itemnumber) { this.itemnumber = itemnumber; } public int getOutnumber() { return outnumber; } public void setOutnumber(int outnumber) { this.outnumber = outnumber; } }
import java.util.Objects; import java.util.Scanner; public class WarehouseManagement { public static void main(String[] args) { int choice; Scanner sc = new Scanner(System.in); WarehouseInformation[] arr = new WarehouseInformation[5]; arr[0] = new WarehouseInformation("00000001", "0", "0", "0", "0", "0", "0", 30, 0); arr[1] = new WarehouseInformation("0", "0", "0", "0", "0", "0", "0", 0, 0); arr[2] = new WarehouseInformation("0", "0", "0", "0", "0", "0", "0", 0, 0); arr[3] = new WarehouseInformation("0", "0", "0", "0", "0", "0", "0", 0, 0); arr[4] = new WarehouseInformation("0", "0", "0", "0", "0", "0", "0", 0, 0); while (true) { menu(); System.out.println("请输入你的选择:"); choice = sc.nextInt(); switch (choice) { case 1: { in(arr); break; } case 2: { xiu(arr); break; } case 3: { chuku(arr); break; } case 4: { chaxun(arr); break; } default: { System.out.println("改选项不存在"); break; } } } } public static void menu() { System.out.println("***********************************************************"); System.out.println(" 石家庄铁道大学前进22软件开发有限公司"); System.out.println(" 仓库管理系统2022版"); System.out.println("***********************************************************"); System.out.println(" 1、商品入库管理"); System.out.println(" 2、商品信息修改"); System.out.println(" 3、商品出库管理"); System.out.println(" 4、仓库盘点管理"); System.out.println("**********************************************************"); } public static void in(WarehouseInformation[] arr) { Scanner s = new Scanner(System.in); String no; String name; String information; String time1; String wnumber; String wspace; char c; while (true) { while (true) { System.out.println("请输入商品编码"); no = s.next(); System.out.println("请输入商品名称"); name = s.next(); System.out.println("请输入供货商信息"); information = s.next(); System.out.println("请输入入库时间"); time1 = s.next(); System.out.println("请输入存放仓库号"); wnumber = s.next(); System.out.println("请输入存放位置"); wspace = s.next(); if ((no.length() == 8) && (time1.length() == 8) && (wnumber.length() == 3) && (wspace.length() == 8)) { System.out.println("***********************************************************"); System.out.println(" 石家庄铁道大学前进22软件开发有限公司"); System.out.println(" 仓库管理系统2022版"); System.out.println("***********************************************************"); System.out.println(" 商品编号:" + no); System.out.println(" 商品名称:" + name); System.out.println(" 供货商信息:" + information); System.out.println(" 入库时间:" + time1); System.out.println(" 存放仓库号:" + wnumber); System.out.println(" 存放位置信息:" + wspace); System.out.println(" 入库商品数量:100"); System.out.println("**********************************************************"); break; } else { System.out.println("录入错误"); } } System.out.println("***********************************************************"); System.out.println(" 石家庄铁道大学前进22软件开发有限公司"); System.out.println(" 仓库管理系统2022版"); System.out.println("***********************************************************"); System.out.println(" 商品编号:" + no); System.out.println(" 商品名称:" + name); System.out.println(" 供货商信息:" + information); System.out.println(" 入库时间:" + time1); System.out.println(" 存放仓库号:" + wnumber); System.out.println(" 存放位置信息:" + wspace); System.out.println(" 入库商品数量:100"); System.out.println(" 该商品入库操作已完成,是否提交(Y/N)"); System.out.println("**********************************************************"); c = s.next().charAt(0); if (c == 'Y') { for (int i = 0; i < 5; i++) { if (arr[i].getItemno().equals("0")) { arr[i].setItemno(no); arr[i].setItemname(name); arr[i].setSuppliername(information); arr[i].setWarehousingtime(time1); arr[i].setWarehousenumber(wnumber); arr[i].setWarehouseplace(wspace); arr[i].setItemnumber(100); System.out.println("信息保存成功!"); return; } } } } } public static void display(int i, WarehouseInformation[] arr, int choice) { System.out.println("***********************************************************"); System.out.println(" 石家庄铁道大学前进22软件开发有限公司"); System.out.println(" 仓库管理系统2022版"); System.out.println("***********************************************************"); System.out.println(" 1、商品编号:" + arr[i].getItemno()); System.out.println(" 2、商品名称:" + arr[i].getItemname()); System.out.println(" 3、供货商信息:" + arr[i].getSuppliername()); System.out.println(" 4、入库时间:" + arr[i].getWarehousingtime()); System.out.println(" 5、存放仓库号:" + arr[i].getWarehousenumber()); System.out.println(" 6、存放位置信息:" + arr[i].getWarehouseplace()); System.out.println(" 7、入库商品数量:" + arr[i].getItemnumber()); System.out.println(" 请选择需要修改的信息编号(1-7):" + choice); System.out.println(" 请输入修改后的商品编号:"); System.out.println("**********************************************************"); } public static void xiu(WarehouseInformation[] arr) { Scanner s1 = new Scanner(System.in); String no1; String name; String information; String time1; String wnumber; String wspace; int number; int hao; int count = 0; char c; while (true) { System.out.println("***********************************************************"); System.out.println(" 石家庄铁道大学前进22软件开发有限公司"); System.out.println(" 仓库管理系统2022版"); System.out.println("***********************************************************"); System.out.println(" 请输入商品编号:"); System.out.println("**********************************************************"); String no; no = s1.next(); for (int i = 0; i < 5; i++) { if (no.equals(arr[i].getItemno())) { count++; System.out.println("***********************************************************"); System.out.println(" 石家庄铁道大学前进22软件开发有限公司"); System.out.println(" 仓库管理系统2022版"); System.out.println("***********************************************************"); System.out.println(" 1、商品编号:" + arr[i].getItemno()); System.out.println(" 2、商品名称:" + arr[i].getItemname()); System.out.println(" 3、供货商信息:" + arr[i].getSuppliername()); System.out.println(" 4、入库时间:" + arr[i].getWarehousingtime()); System.out.println(" 5、存放仓库号:" + arr[i].getWarehousenumber()); System.out.println(" 6、存放位置信息:" + arr[i].getWarehouseplace()); System.out.println(" 7、入库商品数量:" + arr[i].getItemnumber()); System.out.println(" 请选择需要修改的信息编号(1-7):"); System.out.println("**********************************************************"); hao = s1.nextInt(); switch (hao) { case 1: { display(i, arr, 1); no1 = s1.next(); System.out.println(" 修改信息已完成,是否提交(Y/N)"); c = s1.next().charAt(0); if (c == 'Y') { arr[i].setItemno(no1); System.out.println("信息保存成功!"); } else { return; } break; } case 2: { display(i, arr, 2); name = s1.next(); System.out.println(" 修改信息已完成,是否提交(Y/N)"); c = s1.next().charAt(0); if (c == 'Y') { arr[i].setItemname(name); System.out.println("信息保存成功!"); } else { return; } break; } case 3: { display(i, arr, 3); information = s1.next(); System.out.println(" 修改信息已完成,是否提交(Y/N)"); c = s1.next().charAt(0); if (c == 'Y') { arr[i].setSuppliername(information); System.out.println("信息保存成功!"); } else { return; } break; } case 4: { display(i, arr, 4); time1 = s1.next(); System.out.println(" 修改信息已完成,是否提交(Y/N)"); c = s1.next().charAt(0); if (c == 'Y') { arr[i].setWarehousingtime(time1); System.out.println("信息保存成功!"); } else { return; } break; } case 5: { display(i, arr, 5); wnumber = s1.next(); System.out.println(" 修改信息已完成,是否提交(Y/N)"); c = s1.next().charAt(0); if (c == 'Y') { arr[i].setWarehousenumber(wnumber); System.out.println("信息保存成功!"); } else { return; } break; } case 6: { display(i, arr, 6); wspace = s1.next(); System.out.println(" 修改信息已完成,是否提交(Y/N)"); c = s1.next().charAt(0); if (c == 'Y') { arr[i].setWarehouseplace(wspace); System.out.println("信息保存成功!"); } else { return; } break; } case 7: { display(i, arr, 7); number = s1.nextInt(); System.out.println(" 修改信息已完成,是否提交(Y/N)"); c = s1.next().charAt(0); if (c == 'Y') { arr[i].setItemnumber(number); System.out.println("信息保存成功!"); } else { return; } break; } default: { System.out.println("该选项不存在"); return; } } } } if (count == 0) { System.out.println("库中没有该商品"); } } } public static void chuku(WarehouseInformation[] arr) { String no; String time2 = ""; int out = 0; char c; Scanner s2 = new Scanner(System.in); int count = 0; int flag = 0; while (true) { System.out.println("***********************************************************"); System.out.println(" 石家庄铁道大学前进22软件开发有限公司"); System.out.println(" 仓库管理系统2022版"); System.out.println("***********************************************************"); System.out.println(" 请输入商品编号:"); System.out.println("**********************************************************"); no = s2.next(); for (int i = 0; i < 5; i++) { if (no.equals(arr[i].getItemno())) { while (true) { System.out.println("***********************************************************"); System.out.println(" 石家庄铁道大学前进22软件开发有限公司"); System.out.println(" 仓库管理系统2022版"); System.out.println("***********************************************************"); System.out.println(" 1、商品编号:" + arr[i].getItemno()); System.out.println(" 2、商品名称:" + arr[i].getItemname()); System.out.println(" 3、供货商信息:" + arr[i].getSuppliername()); System.out.println(" 4、入库时间:" + arr[i].getWarehousingtime()); System.out.println(" 5、存放仓库号:" + arr[i].getWarehousenumber()); System.out.println(" 6、存放位置信息:" + arr[i].getWarehouseplace()); System.out.println(" 7、入库商品数量:" + arr[i].getItemnumber()); System.out.println(" 出库时间:"); time2 = s2.next(); System.out.println(" 出库数量:"); System.out.println("**********************************************************"); out = s2.nextInt(); if (out < arr[i].getItemnumber()) { System.out.println(" 修改信息已完成,是否提交(Y/N)"); c = s2.next().charAt(0); if (c == 'Y') { flag = 1; break; } } else { System.out.println("您输入的出库量错误,请重新输入"); } } if (flag == 1) { arr[i].setOutnumber(out); arr[i].setShipmenttime(time2); System.out.println("信息保存成功!"); break; } } else { count++; } } if (count == 5) { System.out.println("库中没有该商品"); } } } public static void chaxun(WarehouseInformation[] arr) { System.out.println("***********************************************************"); System.out.println(" 石家庄铁道大学前进22软件开发有限公司"); System.out.println(" 仓库管理系统2022版"); System.out.println("***********************************************************"); System.out.println("1、\t商品编号:" + arr[0].getItemno() + "、商品名称:" + arr[0].getItemname() + "、库存数量:" + (arr[0].getItemnumber() - arr[0].getOutnumber())); System.out.println("2、\t商品编号:" + arr[1].getItemno() + "、商品名称:" + arr[1].getItemname() + "、库存数量:" + (arr[1].getItemnumber() - arr[1].getOutnumber())); System.out.println("3、\t商品编号:" + arr[2].getItemno() + "、商品名称:" + arr[2].getItemname() + "、库存数量:" + (arr[2].getItemnumber() - arr[2].getOutnumber())); System.out.println("4、\t商品编号:" + arr[3].getItemno() + "、商品名称:" + arr[3].getItemname() + "、库存数量:" + (arr[3].getItemnumber() - arr[3].getOutnumber())); System.out.println("5、\t商品编号:" + arr[4].getItemno() + "、商品名称:" + arr[4].getItemname() + "、库存数量:" + (arr[4].getItemnumber() - arr[4].getOutnumber())); System.out.println("…………………………………………………."); System.out.println("**********************************************************"); } }
在一些重复代码上我们进行了封装,从而节省空间
标签:arr,String,9.16,System,println,public,out From: https://www.cnblogs.com/zzqq1314/p/17706646.html