import java.util.Scanner;标签:product,String,9.17,System,println,out,scanner From: https://www.cnblogs.com/lml66/p/17709878.html
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 inNumber;
private int outNumber;
public WarehouseInformation() {
itemNumber = "";
itemName = "";
supplierName = "";
warehousingTime = "";
shipmentTime = "";
warehouseNumber = "";
warehousePlace = "";
inNumber = 0;
outNumber = 0;
}
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 getInNumber() {
return inNumber;
}
public void setInNumber(int inNumber) {
this.inNumber = inNumber;
}
public int getOutNumber() {
return outNumber;
}
public void setOutNumber(int outNumber) {
this.outNumber = outNumber;
}
}
class WarehouseManagement {
private static final int MAX_PRODUCTS = 5;
private static WarehouseInformation[] warehouseProducts = new WarehouseInformation[MAX_PRODUCTS];
private static int productCount = 0;
public static void main(String[] args) {
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("请输入数字(1-4)执行相应功能,输入其他数字退出系统:");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
manageWarehouseIn(scanner);
break;
case 2:
modifyProductInfo(scanner);
break;
case 3:
manageWarehouseOut(scanner);
break;
case 4:
doInventory();
break;
default:
System.out.println("该选项不存在,请重新输入!");
break;
}
}
}
private static void manageWarehouseIn(Scanner scanner) {
if (productCount >= MAX_PRODUCTS) {
System.out.println("仓库已满,无法继续入库!");
return;
}
WarehouseInformation product = new WarehouseInformation();
System.out.println("请输入商品编码:");
String itemNumber = scanner.nextLine();
product.setItemNumber(itemNumber);
System.out.println("请输入商品名称:");
String itemName = scanner.nextLine();
product.setItemName(itemName);
System.out.println("请输入供货商信息:");
String supplierName = scanner.nextLine();
product.setSupplierName(supplierName);
System.out.println("请输入入库时间(格式:yyyyMMdd):");
String warehousingTime = scanner.nextLine();
product.setWarehousingTime(warehousingTime);
System.out.println("请输入存放仓库号:");
String warehouseNumber = scanner.nextLine();
product.setWarehouseNumber(warehouseNumber);
System.out.println("请输入存放位置信息(格式:XXXXYYZZ):");
String warehousePlace = scanner.nextLine();
product.setWarehousePlace(warehousePlace);
System.out.println("请输入入库商品数量:");
int inNumber = scanner.nextInt();
product.setInNumber(inNumber);
scanner.nextLine();
System.out.println("商品信息如下:");
displayProductInfo(product);
System.out.println("该商品入库操作已完成,是否提交(Y/N):");
String submitChoice = scanner.nextLine();
if (submitChoice.equalsIgnoreCase("Y")) {
warehouseProducts[productCount++] = product;
System.out.println("商品信息已提交!");
} else {
System.out.println("商品信息未提交!");
}
}
private static void displayProductInfo(WarehouseInformation product) {
System.out.println("***********************************************************");
System.out.println("石家庄铁道大学前进22软件开发有限公司");
System.out.println("仓库管理系统2022版");
System.out.println("***********************************************************");
System.out.println("商品编号:" + product.getItemNumber());
System.out.println("商品名称:" + product.getItemName());
System.out.println("供货商信息:" + product.getSupplierName());
System.out.println("入库时间:" + product.getWarehousingTime());
System.out.println("存放仓库号:" + product.getWarehouseNumber());
System.out.println("存放位置信息:" + product.getWarehousePlace());
System.out.println("入库商品数量:" + product.getInNumber());
}
private static void modifyProductInfo(Scanner scanner) {
System.out.println("请输入商品编号:");
String itemNumber = scanner.nextLine();
int index = findProductIndex(itemNumber);
if (index == -1) {
System.out.println("库中没有该商品!");
return;
}
WarehouseInformation product = warehouseProducts[index];
displayProductInfo(product);
System.out.println("请选择需要修改的信息编号(1-7):");
int modifyChoice = scanner.nextInt();
scanner.nextLine(); // 消耗换行符
switch (modifyChoice) {
case 1:
System.out.println("请输入修改后的商品编号:");
String newItemNumber = scanner.nextLine();
product.setItemNumber(newItemNumber);
break;
case 2:
System.out.println("请输入修改后的商品名称:");
String newItemName = scanner.nextLine();
product.setItemName(newItemName);
break;
case 3:
System.out.println("请输入修改后的供货商信息:");
String newSupplierName = scanner.nextLine();
product.setSupplierName(newSupplierName);
break;
case 4:
System.out.println("请输入修改后的入库时间(格式:yyyyMMdd):");
String newWarehousingTime = scanner.nextLine();
product.setWarehousingTime(newWarehousingTime);
break;
case 5:
System.out.println("请输入修改后的存放仓库号:");
String newWarehouseNumber = scanner.nextLine();
product.setWarehouseNumber(newWarehouseNumber);
break;
case 6:
System.out.println("请输入修改后的存放位置信息(格式:XXXXYYZZ):");
String newWarehousePlace = scanner.nextLine();
product.setWarehousePlace(newWarehousePlace);
break;
case 7:
System.out.println("请输入修改后的商品数量:");
int newInNumber = scanner.nextInt();
product.setInNumber(newInNumber);
break;
default:
System.out.println("该选项不存在,请重新输入!");
break;
}
System.out.println("是否保存修改信息(Y/N):");
String saveChoice = scanner.nextLine();
if (saveChoice.equalsIgnoreCase("Y")) {
System.out.println("修改信息已保存!");
} else {
System.out.println("修改信息未保存!");
}
}
private static int findProductIndex(String itemNumber) {
for (int i = 0; i < productCount; i++) {
if (warehouseProducts[i].getItemNumber().equals(itemNumber)) {
return i;
}
}
return -1;
}
private static void manageWarehouseOut(Scanner scanner) {
System.out.println("请输入商品编号:");
String itemNumber = scanner.nextLine();
int index = findProductIndex(itemNumber);
if (index == -1) {
System.out.println("库中没有该商品!");
return;
}
WarehouseInformation product = warehouseProducts[index];
displayProductInfo(product);
System.out.println("请输入出库时间(格式:yyyyMMdd):");
String shipmentTime = scanner.nextLine();
product.setShipmentTime(shipmentTime);
System.out.println("请输入出库数量:");
int outNumber = scanner.nextInt();
product.setOutNumber(outNumber);
scanner.nextLine();
if (outNumber <= product.getInNumber()) {
System.out.println("出库操作已完成!");
} else {
System.out.println("出库数量大于库存数量,出库操作失败!");
product.setShipmentTime("");
product.setOutNumber(0);
}
}
private static void doInventory() {
System.out.println("仓库盘点功能暂未实现!");
}
}