public 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;
// 构造方法,用于赋初值
public WarehouseInformation(String itemno, String itemname, String suppliername, String warehousingtime, String shipmenttime, String warehousenumber, String warehouseplace, int itemnumber, int outnumber) {
this.itemno = itemno;
this.itemname = itemname;
this.suppliername = suppliername;
this.warehousingtime = warehousingtime;
this.shipmenttime = shipmenttime;
this.warehousenumber = warehousenumber;
this.warehouseplace = warehouseplace;
this.itemnumber = itemnumber;
this.outnumber = outnumber;
}
// getter和setter方法
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;
}
}
import java.util.Scanner;标签:scanner,开学,String,System,测试,println,public,out From: https://www.cnblogs.com/gjsgjs/p/17709692.html
public class WarehouseManagement {
private final WarehouseInformation[] warehouseInfos;
private int numOfItems;
public WarehouseManagement() {
warehouseInfos = new WarehouseInformation[5]; // 存储五个商品入库信息
numOfItems = 0;
}
// 主界面
public void mainMenu() {
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("**********************************************************");
Scanner scanner = new Scanner(System.in);
System.out.print("请输入您的选择(输入数字1-4):");
int choice = scanner.nextInt();
switch (choice) {
case 1:
itemWarehousing();
break;
case 2:
itemin();
// 商品信息修改功能
break;
case 3:
itemout();
// 商品出库管理功能
break;
case 4:
itemnem();
break;
default:
System.out.println("该选项不存在,请重新选择。");
mainMenu();
}
}
public void itemin() {
Scanner scanner = new Scanner(System.in);
System.out.println("***********************************************************");
System.out.println("石家庄铁道大学前进22软件开发有限公司");
System.out.println("仓库管理系统2022版");
System.out.println("***********************************************************");
System.out.println("请输入商品编号:");
String itemno = scanner.nextLine();
// 检查商品信息是否存在
boolean itemExist = false;
int index = -1;
for (int i = 0; i < numOfItems; i++) {
if (warehouseInfos[i].getItemno().equals(itemno)) {
itemExist = true;
index = i;
break;
}
}
if (!itemExist) {
System.out.println("库中没有该商品,请重新输入商品编号。");
itemin(); // 返回商品信息修改界面
return;
}
WarehouseInformation warehouseInfo = warehouseInfos[index];
Scanner confirmScanner = new Scanner(System.in);
System.out.println("***********************************************************");
System.out.println("石家庄铁道大学前进22软件开发有限公司");
System.out.println("仓库管理系统2022版");
System.out.println("***********************************************************");
System.out.println("1、商品编号:" + warehouseInfo.getItemno());
System.out.println("2、商品名称:" + warehouseInfo.getItemname());
System.out.println("3、供货商信息:" + warehouseInfo.getSuppliername());
System.out.println("4、入库时间:" + warehouseInfo.getWarehousingtime());
System.out.println("5、存放仓库号:" + warehouseInfo.getWarehousenumber());
System.out.println("6、存放位置信息:" + warehouseInfo.getWarehouseplace());
System.out.println("7、商品数量:" + warehouseInfo.getItemnumber());
System.out.println("请选择需要修改的信息编号(1-7):");
int choice = confirmScanner.nextInt();
switch (choice) {
case 1:
// 商品编号无法修改,不做任何操作
break;
case 2:
System.out.println("请输入修改后的商品名称:");
String modifiedItemName = scanner.nextLine();
warehouseInfo.setItemname(modifiedItemName);
break;
case 3:
System.out.println("请输入修改后的供货商信息:");
String modifiedSupplierName = scanner.nextLine();
warehouseInfo.setSuppliername(modifiedSupplierName);
break;
case 4:
System.out.println("请输入修改后的入库时间:");
String modifiedWarehousingTime = scanner.nextLine();
warehouseInfo.setWarehousingtime(modifiedWarehousingTime);
break;
case 5:
System.out.println("请输入修改后的存放仓库号:");
String modifiedWarehousenumber = scanner.nextLine();
warehouseInfo.setWarehousenumber(modifiedWarehousenumber);
break;
case 6:
System.out.println("请输入修改后的存放位置信息:");
String modifiedWarehouseplace = scanner.nextLine();
warehouseInfo.setWarehouseplace(modifiedWarehouseplace);
break;
case 7:
System.out.println("请输入修改后的商品数量:");
int modifiedItemNumber = scanner.nextInt();
warehouseInfo.setItemnumber(modifiedItemNumber);
break;
default:
System.out.println("该选项不存在,请重新选择。");
mainMenu();
return;
}
Scanner saveScanner = new Scanner(System.in);
System.out.println("该商品信息已修改,是否保存提交(Y/N):");
String confirm = saveScanner.nextLine();
if (confirm.equalsIgnoreCase("Y")) {
System.out.println("商品信息已保存并返回主界面。");
mainMenu();
} else if (confirm.equalsIgnoreCase("N")) {
itemin(); // 返回商品信息修改界面
} else {
System.out.println("输入错误,请重新选择。");
mainMenu();
}
}
private void itemnem() {
}
private void itemout() {
Scanner scanner = new Scanner(System.in);
System.out.println("***********************************************************");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司");
System.out.println(" 仓库管理系统2022版");
System.out.println("***********************************************************");
System.out.println(" 请输入商品编号:");
String itemno = scanner.nextLine();
System.out.println("**********************************************************");
}
// 商品入库管理
public void itemWarehousing() {
Scanner scanner = new Scanner(System.in);
System.out.println("***********************************************************");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司");
System.out.println(" 仓库管理系统2022版");
System.out.println("***********************************************************");
System.out.println("商品编号:");
String itemno = scanner.nextLine();
System.out.println("商品名称:");
String itemname = scanner.nextLine();
System.out.println("供货商信息:");
String suppliername = scanner.nextLine();
System.out.println("入库时间:");
String warehousingtime = scanner.nextLine();
System.out.println("存放仓库号:");
String warehousenumber = scanner.nextLine();
System.out.println("存放位置信息:");
String warehouseplace = scanner.nextLine();
System.out.println("入库商品数量:");
int itemnumber = scanner.nextInt();
// 检查录入格式是否正确
if (!checkInputFormat(itemno, warehousingtime, warehousenumber, warehouseplace)) {
System.out.println("录入错误,请重新录入正确的信息。");
itemWarehousing();
return;
}
Scanner confirmScanner = new Scanner(System.in);
System.out.println("***********************************************************");
System.out.println(" 石家庄铁道大学前进22软件开发有限公司");
System.out.println(" 仓库管理系统2022版");
System.out.println("***********************************************************");
System.out.println(" 商品编号:" + itemno);
System.out.println(" 商品名称:" + itemname);
System.out.println(" 供货商信息:" + suppliername);
System.out.println(" 入库时间:" + warehousingtime);
System.out.println(" 存放仓库号:" + warehousenumber);
System.out.println(" 存放位置信息:" + warehouseplace);
System.out.println(" 入库商品数量:" + itemnumber);
System.out.println("该商品入库操作已完成,是否提交(Y/N):");
String confirm = confirmScanner.nextLine();
if (confirm.equalsIgnoreCase("Y")) {
WarehouseInformation warehouseInfo = new WarehouseInformation(itemno, itemname, suppliername, warehousingtime, "", warehousenumber, warehouseplace, itemnumber, 0);
warehouseInfos[numOfItems] = warehouseInfo;
numOfItems++;
System.out.println("商品信息已存储到相应的数组中,并返回主界面。");
mainMenu();
} else if (confirm.equalsIgnoreCase("N")) {
itemWarehousing(); // 返回商品入库界面
} else {
System.out.println("输入错误,请重新选择。");
mainMenu();
}
}
// 检查录入格式是否正确
public boolean checkInputFormat(String itemno, String warehousingtime, String warehousenumber, String warehouseplace) {
// 自定义格式检查逻辑
// 返回 true 或 false
// 示例:检查itemno是否为8位数字
if (itemno.matches("\\d{8}")) {
return true;
} else {
return false;
}
}
public static void main(String[] args) {
WarehouseManagement warehouseManagement = new WarehouseManagement();
warehouseManagement.mainMenu();
}
}