import java.util.Scanner;
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;
// Getters and Setters for all variables
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;
}
}
class WarehouseManagement {
private WarehouseInformation[] warehouseInformationArray = new WarehouseInformation[5];
private int currentIndex = 0;
public void start() {
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();
switch (choice) {
case 1:
addWarehouseInformation(scanner);
break;
case 2:
modifyWarehouseInformation(scanner);
break;
case 3:
performGoodsShipment(scanner);
break;
case 4:
performInventoryCheck();
break;
default:
System.out.println("该选项不存在,请重新输入。");
}
}
}
private void addWarehouseInformation(Scanner scanner) {
WarehouseInformation info = new WarehouseInformation();
System.out.println("请输入商品编码:");
info.setItemno(scanner.next());
System.out.println("请输入商品名称:");
info.setItemname(scanner.next());
System.out.println("请输入供货商信息:");
info.setSuppliername(scanner.next());
System.out.println("请输入入库时间(格式:yyyyMMdd):");
info.setWarehousingtime(scanner.next());
System.out.println("请输入存放仓库号:");
info.setWarehousenumber(scanner.next());
System.out.println("请输入存放位置信息(格式:XXXXXXXX):");
info.setWarehouseplace(scanner.next());
System.out.println("请输入入库商品数量:");
info.setItemnumber(scanner.nextInt());
// Check for errors in input and handle accordingly
if (validateInput(info)) {
System.out.println("录入错误,请重新录入正确信息。");
return;
}
System.out.println("***********************************************************");
System.out.println("商品编号:" + info.getItemno());
System.out.println("商品名称:" + info.getItemname());
System.out.println("供货商信息:" + info.getSuppliername());
System.out.println("入库时间:" + info.getWarehousingtime());
System.out.println("存放仓库号:" + info.getWarehousenumber());
System.out.println("存放位置信息:" + info.getWarehouseplace());
System.out.println("入库商品数量:" + info.getItemnumber());
System.out.print("该商品入库操作已完成,是否提交(Y/N):");
String submitChoice = scanner.next();
if (submitChoice.equalsIgnoreCase("Y")) {
warehouseInformationArray[currentIndex] = info;
currentIndex++;
}
}
private void modifyWarehouseInformation(Scanner scanner) {
System.out.println("请输入商品编号:");
String itemNoToModify = scanner.next();
boolean found = false;
for (int i = 0; i < currentIndex; i++) {
WarehouseInformation info = warehouseInformationArray[i];
if (info.getItemno().equals(itemNoToModify)) {
found = true;
System.out.println("1、商品编号:" + info.getItemno());
System.out.println("2、商品名称:" + info.getItemname());
System.out.println("3、供货商信息:" + info.getSuppliername());
System.out.println("4、入库时间:" + info.getWarehousingtime());
System.out.println("5、存放仓库号:" + info.getWarehousenumber());
System.out.println("6、存放位置信息:" + info.getWarehouseplace());
System.out.println("7、入库商品数量:" + info.getItemnumber());
System.out.print("请选择需要修改的信息编号(1-7):");
int fieldToModify = scanner.nextInt();
switch (fieldToModify) {
case 1:
System.out.print("请输入修改后的商品编号:");
info.setItemno(scanner.next());
break;
case 2:
System.out.print("请输入修改后的商品名称:");
info.setItemname(scanner.next());
break;
case 3:
System.out.print("请输入修改后的供货商信息:");
info.setSuppliername(scanner.next());
break;
case 4:
System.out.print("请输入修改后的入库时间(格式:yyyyMMdd):");
info.setWarehousingtime(scanner.next());
break;
case 5:
System.out.print("请输入修改后的存放仓库号:");
info.setWarehousenumber(scanner.next());
break;
case 6:
System.out.print("请输入修改后的存放位置信息(格式:XXXXXXXX):");
info.setWarehouseplace(scanner.next());
break;case 7:
System.out.print("请输入修改后的入库商品数量:");
info.setItemnumber(scanner.nextInt());
break;
default:
System.out.println("该选项不存在,请重新输入。");
break;
}
System.out.print("是否保存修改信息(Y/N):");
String saveChoice = scanner.next();
if (saveChoice.equalsIgnoreCase("Y")) {
System.out.println("修改已保存。");
} else {
System.out.println("修改未保存。");
}
break;
}
}
if (!found) {
System.out.println("库中没有该商品。");
}
}
private void performGoodsShipment(Scanner scanner) {
System.out.println("请输入商品编号:");
String itemNoToShip = scanner.next();
boolean found = false;
for (int i = 0; i < currentIndex; i++) {
WarehouseInformation info = warehouseInformationArray[i];
if (info.getItemno().equals(itemNoToShip)) {
found = true;
System.out.println("1、商品编号:" + info.getItemno());
System.out.println("2、商品名称:" + info.getItemname());
System.out.println("3、供货商信息:" + info.getSuppliername());
System.out.println("4、入库时间:" + info.getWarehousingtime());
System.out.println("5、存放仓库号:" + info.getWarehousenumber());
System.out.println("6、存放位置信息:" + info.getWarehouseplace());
System.out.println("7、入库商品数量:" + info.getItemnumber());
System.out.print("出库时间:");
String shipmentTime = scanner.next();
info.setShipmenttime(shipmentTime);
System.out.print("出库数量:");
int shippedQuantity = scanner.nextInt();
if (shippedQuantity <= info.getItemnumber()) {
info.setOutnumber(shippedQuantity);
info.setItemnumber(info.getItemnumber() - shippedQuantity);
System.out.println("出库操作已完成。");
} else {
System.out.println("出库数量大于库存数量,请重新输入。");
}
break;
}
}
if (!found) {
System.out.println("库中没有该商品。");
}
}
private void performInventoryCheck() {
System.out.println("***********************************************************");
System.out.println("石家庄铁道大学前进22软件开发有限公司");
System.out.println("仓库管理系统2022版");
System.out.println("***********************************************************");
int itemCount = 0;
for (int i = 0; i < currentIndex; i++) {
WarehouseInformation info = warehouseInformationArray[i];
itemCount++;
System.out.println(itemCount + "、商品编号:" + info.getItemno() + "、商品名称:" + info.getItemname() + "、库存数量:" + info.getItemnumber());
}
System.out.println("***********************************************************");
}
private boolean validateInput(WarehouseInformation info) {
// You can add your validation logic here
// For example, check if itemno is 8 digits, warehousingtime format, etc.
return false;
}
}
public class WarehouseManagementSystem {
public static void main(String[] args) {
WarehouseManagement warehouseManagement = new WarehouseManagement();
warehouseManagement.start();
}
}
标签:info,scanner,管理系统,仓库,System,String,println,out From: https://www.cnblogs.com/yindantong/p/17708742.html