Import java.util.Scanner;
Public class WarehouseManagement {
Static int numOfItems = 0;
Static WarehouseInformation[] warehouseInformations = new WarehouseInformation[5];
Public static void main(String[] args) {
initializeData();
Scanner scanner = new Scanner(System.in);
While (true) {
printMainMenu();
System.out.println(“请输入数字选择功能:”);
Int option = scanner.nextInt();
Switch (option) {
Case 1:
addCommodity(scanner);
break;
case 2:
modifyWarehouse(scanner);
break;
case 3:
outboundWarehouse(scanner);
break;
case 4:
countGoods();
break;
default:
System.out.println(“该选项不存在”);
}
}
}
Private static void initializeData() {
warehouseInformations[0] = new WarehouseInformation(“20224085”, “华为笔记本电脑”, “河北省正大光明有限公司”, “003”, “0180350”, 100, 0);
warehouseInformations[1] = new WarehouseInformation(“20224086”, “Apple iPhone”, “Guangdong Xinrui Technology Co., Ltd.”, “004”, “0180351”, 50, 10);
warehouseInformations[2] = new WarehouseInformation(“20224087”, “Samsung Tablet”, “Shanghai Letian Electronics Co., Ltd.”, “005”, “0180352”, 80, 20);
warehouseInformations[3] = new WarehouseInformation(“20224088”, “Huawei Smartphone”, “Beijing Zhongxing Technology Co., Ltd.”, “006”, “0180353”, 120, 50);
warehouseInformations[4] = new WarehouseInformation(“20224089”, “Xiaomi TV”, “Zhejiang Rongyao Electronics Co., Ltd.”, “007”, “0180354”, 60, 30);
numOfItems = 5;
}
Private static void printMainMenu() {
System.out.println(“***********************************************************”);
System.out.println(“ 石家庄铁道大学前进22软件开发有限公司”);
System.out.println(“ 仓库管理系统2022版”);
System.out.println(“ 1、商品入库管理”);
System.out.println(“ 2、商品信息修改”);
System.out.println(“ 3、商品出库管理”);
System.out.println(“ 4、仓库盘点管理”);
System.out.println(“***********************************************************”);
}
Private static void addCommodity(Scanner scanner) {
printItemPrompt(“商品编码”);
String itemno = scanner.next();
printItemPrompt(“商品名称”);
String itemname = scanner.next();
printItemPrompt(“供货商信息”);
String suppliername = scanner.next();
printItemPrompt(“入库时间”);
String warehousingtime = scanner.next();
printItemPrompt(“存放仓库号”);
String warehousenumber = scanner.next();
printItemPrompt(“存放位置信息”);
String warehouseplace = scanner.next();
printItemPrompt(“入库商品数量”);
int itemnumber = scanner.nextInt();
printItemInfo(itemno, itemname, suppliername, warehousingtime, warehousenumber, warehouseplace, itemnumber);
System.out.println(“该商品入库操作已完成,是否提交(Y/N):”);
String confirm = scanner.next();
If (confirm.equalsIgnoreCase(“Y”)) {
warehouseInformations[numOfItems] = new WarehouseInformation(itemno, itemname, suppliername, warehousenumber, warehouseplace, itemnumber, 0);
numOfItems++;
System.out.println(“提交成功!”);
}
}
Private static void modifyWarehouse(Scanner scanner) {
printItemPrompt(“商品编号”);
String itemno = scanner.next();
WarehouseInformation warehouseInformation = findItemByNo(itemno);
If (warehouseInformation == null) {
System.out.println(“库中没有该商品”);
Return;
}
printItemInfo(warehouseInformation);
System.out.println(“请输入需要修改的信息编号(1-7):”);
Int fieldNum = scanner.nextInt();
Scanner.nextLine(); // 读取换行符
String[] fieldNames = { “商品编号”, “商品名称”, “供货商信息”, “入库时间”, “存放仓库号”, “存放位置信息”, “入库商品数量” };
String fieldName = fieldNames[fieldNum – 1];
System.out.println(“请输入修改后的” + fieldName + “:”);
String newVal = scanner.nextLine();
printItemPrompt(“是否保存(Y/N):”);
String confirm = scanner.next();
If (confirm.equalsIgnoreCase(“Y”)) {
modifyData(warehouseInformation, fieldNum, newVal);
System.out.println(“保存成功!”);
}
}
Private static void outboundWarehouse(Scanner scanner) {
printItemPrompt(“商品编号”);
String itemno = scanner.next();
WarehouseInformation warehouseInformation = findItemByNo(itemno);
If (warehouseInformation == null) {
System.out.println(“库中没有该商品”);
Return;
}
printItemInfo(warehouseInformation);
int stockQuantity = warehouseInformation.getItemnumber() – warehouseInformation.getOutnumber();
System.out.println(“全部库存数量:” + stockQuantity);
System.out.println(“请输入出库数量:”);
Int outboundQuantity = scanner.nextInt();
If (outboundQuantity > stockQuantity) {
System.out.println(“超过库存数量!”);
Return;
}
printItemPrompt(“是否保存出库信息(Y/N):”);
String confirm = scanner.next();
If (confirm.equalsIgnoreCase(“Y”)) {
modifyData(warehouseInformation, 8, String.valueOf(outboundQuantity));
System.out.println(“保存成功!”);
}
}
Private static void countGoods() {
For (int I = 0; I < numOfItems; i++) {
System.out.println(“商品编号:” + warehouseInformations[i].getItemno());
System.out.println(“商品名称:” + warehouseInformations[i].getItemname());
System.out.println(“库存数量:” + (warehouseInformations[i].getItemnumber() – warehouseInformations[i].getOutnumber()));
System.out.println(“………………………………………………….”);
}
}
Private static void modifyData(WarehouseInformation warehouseInformation, int fieldNum, String newVal) {
Switch (fieldNum) {
Case 1:
warehouseInformation.setItemno(newVal);
break;
case 2:
warehouseInformation.setItemname(newVal);
break;
case 3:
warehouseInformation.setSuppliername(newVal);
break;
case 4:
warehouseInformation.setWarehousingtime(newVal);
break;
case 5:
warehouseInformation.setWarehousenumber(newVal);
break;
case 6:
warehouseInformation.setWarehouseplace(newVal);
break;
case 7:
warehouseInformation.setItemnumber(Integer.parseInt(newVal));
break;
case 8:
warehouseInformation.setOutnumber(Integer.parseInt(newVal));
break;
default:
System.out.println(“该选项不存在!”);
}
}
Private static WarehouseInformation findItemByNo(String itemno) {
For (int I = 0; I < numOfItems; i++) {
If (warehouseInformations[i].getItemno().equals(itemno)) {
Return warehouseInformations[i];
}
}
Return null;
}
Private static void printItemPrompt(String fieldName) {
System.out.println(“请输入” + fieldName + “:”);
}
Private static void printItemInfo(WarehouseInformation warehouseInformation) {
System.out.println(“1.商品编号:” + warehouseInformation.getItemno());
System.out.println(“2.商品名称:” + warehouseInformation.getItemname());
System.out.println(“3.供货商信息:” + warehouseInformation.getSuppliername());
System.out.println(“4.入库时间:” + warehouseInformation.getWarehousingtime());
System.out.println(“5.存放仓库号:” + warehouseInformation.getWarehousenumber());
System.out.println(“6.存放位置信息:” + warehouseInformation.getWarehouseplace());
System.out.println(“7.入库商品数量:” + warehouseInformation.getItemnumber());
System.out.println(“**********************************************************”);
}
Private static void printItemInfo(String itemno, String itemname, String suppliername, String warehousingtime, String warehousenumber, String warehouseplace, int itemnumber) {
System.out.println(“1.商品编号:” + itemno);
System.out.println(“2.商品名称:” + itemname);
System.out.println(“3.供货商信息:” + suppliername);
System.out.println(“4.入库时间:” + warehousingtime);
System.out.println(“5.存放仓库号:” + warehousenumber);
System.out.println(“6.存放位置信息:” + warehouseplace);
System.out.println(“7.入库商品数量:” + itemnumber);
System.out.println(“**********************************************************”);
}
}
标签:scanner,String,9.17,System,四次,分解,warehouseInformation,println,out From: https://www.cnblogs.com/zeyangshuaige/p/17709629.html