public class WarehouseInformation {
private String itemnumber;
private String itemname;
private String suppliername;
private String warehousingtime;
private String shipmenttime;
private String warehousenumber;
private String warehouseplace;
private int itemnumberQuantity;
private int outnumber;
// Constructor
public WarehouseInformation(String itemnumber, String itemname, String suppliername,
String warehousingtime, String shipmenttime, String warehousenumber,
String warehouseplace, int itemnumberQuantity, int outnumber) {
this.itemnumber = itemnumber;
this.itemname = itemname;
this.suppliername = suppliername;
this.warehousingtime = warehousingtime;
this.shipmenttime = shipmenttime;
this.warehousenumber = warehousenumber;
this.warehouseplace = warehouseplace;
this.itemnumberQuantity = itemnumberQuantity;
this.outnumber = outnumber;
}
// Getters and Setters
public String getItemnumber() { return itemnumber; }
public void setItemnumber(String itemnumber) { this.itemnumber = itemnumber; }
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 getItemnumberQuantity() { return itemnumberQuantity; }
public void setItemnumberQuantity(int itemnumberQuantity) { this.itemnumberQuantity = itemnumberQuantity; }
public int getOutnumber() { return outnumber; }
public void setOutnumber(int outnumber) { this.outnumber = outnumber; }
}
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
private ArrayList
public void mainMenu() {
Scanner scanner = new Scanner(System.in);
while (true) {
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.print("请输入选项(1-4):");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case 1:
manageWarehouseEntry(scanner);
break;
case 2:
modifyItemInfo(scanner);
break;
case 3:
manageWarehouseExit(scanner);
break;
case 4:
inventoryCheck();
break;
default:
System.out.println("该选项不存在!");
break;
}
}
}
private void manageWarehouseEntry(Scanner scanner) {
System.out.println("***********************************************************");
System.out.println("商品入库管理");
System.out.println("***********************************************************");
String itemnumber, itemname, suppliername, warehousingtime, shipmenttime, warehousenumber, warehouseplace;
int itemnumberQuantity;
while (true) {
System.out.print("请输入商品编号(8位数字):");
itemnumber = scanner.nextLine();
if (itemnumber.matches("\\d{8}")) break;
System.out.println("录入错误,请重新输入商品编号!");
}
System.out.print("请输入商品名称:");
itemname = scanner.nextLine();
System.out.print("请输入供货商信息:");
suppliername = scanner.nextLine();
while (true) {
System.out.print("请输入入库时间(YYYYMMDD):");
warehousingtime = scanner.nextLine();
if (warehousingtime.matches("\\d{8}")) break;
System.out.println("录入错误,请重新输入入库时间!");
}
System.out.print("请输入存放仓库号(3位):");
warehousenumber = scanner.nextLine();
if (!warehousenumber.matches("\\d{3}")) {
System.out.println("录入错误,请重新输入仓库号!");
return;
}
System.out.print("请输入存放位置信息(8位):");
warehouseplace = scanner.nextLine();
if (!warehouseplace.matches("\\d{8}")) {
System.out.println("录入错误,请重新输入存放位置信息!");
return;
}
System.out.print("请输入入库商品数量:");
itemnumberQuantity = scanner.nextInt();
scanner.nextLine(); // Consume newline
System.out.println("***********************************************************");
System.out.println("商品编号:" + itemnumber);
System.out.println("商品名称:" + itemname);
System.out.println("供货商信息:" + suppliername);
System.out.println("入库时间:" + warehousingtime);
System.out.println("存放仓库号:" + warehousenumber);
System.out.println("存放位置信息:" + warehouseplace);
System.out.println("入库商品数量:" + itemnumberQuantity);
System.out.println("该商品入库操作已完成,是否提交(Y/N):");
String submit = scanner.nextLine();
if (submit.equalsIgnoreCase("Y")) {
WarehouseInformation info = new WarehouseInformation(itemnumber, itemname, suppliername, warehousingtime, "", warehousenumber, warehouseplace, itemnumberQuantity, 0);
warehouseList.add(info);
System.out.println("商品信息已保存!");
} else {
System.out.println("商品信息未保存!");
}
}
private void modifyItemInfo(Scanner scanner) {
System.out.println("***********************************************************");
System.out.println("商品信息修改");
System.out.println("***********************************************************");
while (true) {
System.out.print("请输入商品编号(8位数字):");
String itemnumber = scanner.nextLine();
if (!itemnumber.matches("\\d{8}")) {
System.out.println("录入错误,请重新输入商品编号!");
continue;
}
WarehouseInformation item = findItemByNumber(itemnumber);
if (item == null) {
System.out.println("库中没有该商品!");
return;
}
System.out.println("***********************************************************");
System.out.println("1、商品编号:" + item.getItemnumber());
System.out.println("2、商品名称:" + item.getItemname());
System.out.println("3、供货商信息:" + item.getSuppliername());
System.out.println("4、入库时间:" + item.getWarehousingtime());
System.out.println("5、存放仓库号:" + item.getWarehousenumber());
System.out.println("6、存放位置信息:" + item.getWarehouseplace());
System.out.println("7、入库商品数量:" + item.getItemnumberQuantity());
System.out.println("***********************************************************");
System.out.print("请选择需要修改的信息编号(1-7):");
int fieldToModify = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (fieldToModify) {
case 1:
System.out.print("请输入新的商品编号:");
itemnumber = scanner.nextLine();
if (itemnumber.matches("\\d{8}")) item.setItemnumber(itemnumber);
else System.out.println("录入错误,商品编号必须为8位数字!");
break;
case 2:
System.out.print("请输入新的商品名称:");
item.setItemname(scanner.nextLine());
break;
case 3:
System.out.print("请输入新的供货商信息:");
item.setSuppliername(scanner.nextLine());
break;
case 4:
System.out.print("请输入新的入库时间(YYYYMMDD):");
item.setWarehousingtime(scanner.nextLine());
break;
case 5:
System.out.print("请输入新的存放仓库号(3位):");
String warehousenumber = scanner.nextLine();
if (warehousenumber.matches("\\d{3}")) item.setWarehousenumber(warehousenumber);
else System.out.println("录入错误,仓库号必须为3位数字!");
break;
case 6:
System.out.print("请输入新的存放位置信息(8位):");
String warehouseplace = scanner.nextLine();
if (warehouseplace.matches("\\d{8}")) item.setWarehouseplace(warehouseplace);
else System.out.println("录入错误,存放位置信息必须为8位数字!");
break;
case 7:
System.out.print("请输入新的入库商品数量:");
item.setItemnumberQuantity(scanner.nextInt());
scanner.nextLine(); // Consume newline
break;
default:
System.out.println("该选项不存在!");
return;
}
System.out.println("***********************************************************");
System.out.println("商品编号:" + item.getItemnumber());
System.out.println("商品名称:" + item.getItemname());
System.out.println("供货商信息:" + item.getSuppliername());
System.out.println("入库时间:" + item.getWarehousingtime());
System.out.println("存放仓库号:" + item.getWarehousenumber());
System.out.println("存放位置信息:" + item.getWarehouseplace());
System.out.println("入库商品数量:" + item.getItemnumberQuantity());
System.out.println("***********************************************************");
System.out.println("是否保存修改(Y/N):");
String saveChanges = scanner.nextLine();
if (saveChanges.equalsIgnoreCase("Y")) {
System.out.println("修改信息已保存!");
} else {
System.out.println("修改信息未保存!");
}
}
}
private void manageWarehouseExit(Scanner scanner) {
System.out.println("***********************************************************");
System.out.println("商品出库管理");
System.out.println("***********************************************************");
while (true) {
System.out.print("请输入商品编号(8位数字):");
String itemnumber = scanner.nextLine();
if (!itemnumber.matches("\\d{8}")) {
System.out.println("录入错误,请重新输入商品编号!");
continue;
}
WarehouseInformation item = findItemByNumber(itemnumber);
if (item == null) {
System.out.println("库中没有该商品!");
return;
}
System.out.println("***********************************************************");
System.out.println("1、商品编号:" + item.getItemnumber());
System.out.println("2、商品名称:" + item.getItemname());
System.out.println("3、供货商信息:" + item.getSuppliername());
System.out.println("4、入库时间:" + item.getWarehousingtime());
System.out.println("5、存放仓库号:" + item.getWarehousenumber());
System.out.println("6、存放位置信息:" + item.getWarehouseplace());
System.out.println("7、入库商品数量:" + item.getItemnumberQuantity());
System.out.println("***********************************************************");
System.out.print("请输入出库时间(YYYYMMDD):");
String shipmenttime = scanner.nextLine();
System.out.print("请输入出库数量:");
int outnumber = scanner.nextInt();
scanner.nextLine(); // Consume newline
if (outnumber > item.getItemnumberQuantity()) {
System.out.println("出库数量不能超过入库数量!");
return;
}
item.setShipmenttime(shipmenttime);
item.setOutnumber(outnumber);
System.out.println("***********************************************************");
System.out.println("商品编号:" + item.getItemnumber());
System.out.println("商品名称:" + item.getItemname());
System.out.println("供货商信息:" + item.getSuppliername());
System.out.println("入库时间:" + item.getWarehousingtime());
System.out.println("存放仓库号:" + item.getWarehousenumber());
System.out.println("存放位置信息:" + item.getWarehouseplace());
System.out.println("入库商品数量:" + item.getItemnumberQuantity());
System.out.println("出库时间:" + item.getShipmenttime());
System.out.println("出库数量:" + item.getOutnumber());
System.out.println("***********************************************************");
System.out.println("是否保存出库信息(Y/N):");
String saveChanges = scanner.nextLine();
if (saveChanges.equalsIgnoreCase("Y")) {
System.out.println("出库信息已保存!");
} else {
System.out.println("出库信息未保存!");
}
}
}
private void inventoryCheck() {
System.out.println("***********************************************************");
System.out.println("仓库盘点管理");
System.out.println("***********************************************************");
for (WarehouseInformation item : warehouseList) {
int totalIn = item.getItemnumberQuantity();
int totalOut = item.getOutnumber();
int currentStock = totalIn - totalOut;
System.out.println("商品编号:" + item.getItemnumber() + "、商品名称:" + item.getItemname() + "、库存数量:" + currentStock);
}
}
private WarehouseInformation findItemByNumber(String itemnumber) {
for (WarehouseInformation item : warehouseList) {
if (item.getItemnumber().equals(itemnumber)) {
return item;
}
}
return null;
}
}
标签:27,scanner,String,System,2024,item,println,out From: https://www.cnblogs.com/dengyizhidai/p/18436749