public class WarehouseInformation { private String itemno; private String itemname; private String suppliername; private String warehousingtime; private String warehousenumber; private String shipmenttime; private String warehouseplace; private int itemnumber; private int outnumber; public WarehouseInformation() { this.itemno=null; this.itemname=null; this.suppliername=null; this.warehousingtime=null; this.warehousenumber=null; this.shipmenttime=null; this.warehouseplace=null; this.itemnumber=0; this.outnumber=0; } public WarehouseInformation(String itemno, String itemname, String suppliername, String warehousingtime, String warehousenumber, String shipmenttime, String warehouseplace, int itemnumber, int outnumber) { this.itemno = itemno; this.itemname = itemname; this.suppliername = suppliername; this.warehousingtime = warehousingtime; this.warehousenumber = warehousenumber; this.shipmenttime = shipmenttime; 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 getWarehousenumber() { return warehousenumber; } public void setWarehousenumber(String warehousenumber) { this.warehousenumber = warehousenumber; } public String getShipmenttime() { return shipmenttime; } public void setShipmenttime(String shipmenttime) { this.shipmenttime = shipmenttime; } 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.Scanner; public class WarehouseManagement { Scanner sc=new Scanner(System.in); public WarehouseInformation[] arr=new WarehouseInformation[10]; public static int size=0; public void manu(){ 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("**********************************************************"); System.out.println("请选择:"); } public boolean determine(){ System.out.print("请选择是否保存结果(Y/N):"); String temp=sc.next(); return !temp.equals("N"); } public String reinput(String s1,int x){ while(s1.length()!=x){ System.out.print("输入失败,请重新输入:"); s1=sc.next(); } return s1; } public void headdisplay(){ System.out.println("***********************************************************"); System.out.println(" 石家庄铁道大学前进22软件开发有限公司"); System.out.println(" 仓库管理系统2022版"); System.out.println("***********************************************************"); } public void display(WarehouseInformation ware){ headdisplay(); System.out.println(" 1、商品编号:"+ware.getItemno()); System.out.println(" 2、商品名称:"+ware.getItemname()); System.out.println(" 3、供货商信息:"+ware.getSuppliername()); System.out.println(" 4、入库时间:"+ware.getWarehousingtime()); System.out.println(" 5、存放仓库号:"+ware.getWarehousenumber()); System.out.println(" 6、存放位置信息:"+ware.getWarehouseplace()); System.out.println(" 7、入库商品数量:"+ware.getItemnumber()); } public void operator1(){ WarehouseInformation w=new WarehouseInformation(); headdisplay(); System.out.print(" 商品编号:"); String s1=sc.next(); reinput(s1,8); w.setItemno(s1); System.out.print(" 商品名称:"); String s2=sc.next(); w.setItemname(s2); System.out.print(" 供货商信息:"); String s3=sc.next(); w.setSuppliername(s3); System.out.print(" 入库时间:"); String s4=sc.next(); reinput(s4,8); w.setItemno(s4); w.setWarehousingtime(s4); System.out.print(" 存放仓库号:"); String s5=sc.next(); reinput(s5,3); w.setItemno(s5); w.setWarehousenumber(s5); System.out.print(" 存放位置信息:"); String s6=sc.next(); reinput(s6,8); w.setWarehouseplace(s6); System.out.print(" 入库商品数量:"); int n1=sc.nextInt(); w.setItemnumber(n1); System.out.println("***********************************************************"); display(w); if(!determine()) return; System.out.println("***********************************************************"); arr[size++]=w; } public void operator2(){ boolean key=true; while(key) { headdisplay(); System.out.print("请输入商品编号:"); String s1=sc.next(); reinput(s1,3); for(int i=0;i<size;i++){ if(arr[i].getItemno().equals(s1)){ display(arr[i]); System.out.print(" 请选择需要修改的信息编号(1-7):"); int temp=sc.nextInt(); if(temp>7){ System.out.println("该选项不存在!"); return; } switch(temp){ case 1: System.out.print("请输入修改后的商品编号:"); String ss=sc.next(); reinput(ss,8); if(!determine()) return; arr[i].setItemno(ss); break; case 2: System.out.print("请输入修改后的商品名称:"); String s2=sc.next(); if(!determine()) return; arr[i].setItemname(s2); break; case 3: System.out.print("请输入修改后的供货商信息:"); String s3=sc.next(); if(!determine()) return; arr[i].setSuppliername(s3); break; case 4: System.out.print("请输入修改后的入库时间:"); String s4=sc.next(); reinput(s4,8); if(!determine()) return; arr[i].setWarehousingtime(s4); break; case 5: System.out.print("请输入修改后的存放仓库号:"); String s5=sc.next(); reinput(s5,8); if(!determine()) return; arr[i].setWarehousenumber(s5); break; case 6: System.out.print("请输入修改后的存放位置信息:"); String s6=sc.next(); reinput(s6,8); if(!determine()) return; arr[i].setWarehouseplace(s6); break; case 7: System.out.print("请输入修改后的商品数量:"); int num=sc.nextInt(); while(num<0){ System.out.print("输入失败,请重新输入:"); num=sc.nextInt(); } if(!determine()) return; arr[i].setItemnumber(num); break; } } } System.out.println("***********************************************************"); } } public void operator3(){ headdisplay(); System.out.print("请输入商品编号:"); String s1=sc.next(); for(int i=0;i<size;i++){ if(arr[i].getItemno().equals(s1)){ display(arr[i]); System.out.print(" 出库时间:"); String str=sc.next(); reinput(str,8); boolean tkey=true; while(tkey){ int num1=0,num2=0; char ch1[]=arr[i].getWarehousingtime().toCharArray(); char ch2[]=str.toCharArray(); for (char value : ch1) { num1 = num1 * 10 + value - '0'; } for (char c : ch2) { num2 = num2 * 10 + c - '0'; } if(num1>=num2){ System.out.print("出库时间早于入库时间,请重新输入:"); str=sc.next(); reinput(str,8); }else{ tkey=false; } } System.out.print(" 出库数量:"); int tt=sc.nextInt(); while(tt>(arr[i].getItemnumber()-arr[i].getOutnumber())){ System.out.print("输入失败,仓库中没有这么多商品,请重新输入:"); tt=sc.nextInt(); } if(!determine()){ arr[i].setShipmenttime(str); arr[i].setOutnumber(tt); break; }else{ operator3(); } } if(i==size-1){ System.out.println("未查询到该商品!"); return; } } } public void operator4(){ headdisplay(); for(int i=0;i<size;i++) { System.out.print(i + 1); System.out.println("、 商品编号:" + arr[i].getItemno() + " 、商品名称:" + arr[i].getItemname() + " 、库存数量:" + (arr[i].getItemnumber() - arr[i].getOutnumber())); } System.out.println("…………………………………………………."); System.out.println("***********************************************************"); } public void open(){ while(true) { manu(); int n=sc.nextInt(); switch (n) { case 1 -> { operator1(); display(arr[0]); } case 2 -> operator2(); case 3 -> operator3(); case 4 -> operator4(); default -> System.out.println("该选项不存在!"); } } } public static void main(String[] args) { WarehouseManagement tmanage=new WarehouseManagement(); tmanage.open(); } }
标签:Java,String,System,sc,代码优化,2023,println,public,out From: https://www.cnblogs.com/Sunyiran/p/17703845.html