信息类WarehouseInformation
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class WarehouseInformation {
private String itemNo;
private String itemName;
private String supplierName;
private String warehousingTime;
private String shipmentTime;
private String warehouseNumber;
public String getWarehousePlace() {
return warehousePlace;
}
public void setWarehousePlace(String warehousePlace) {
this.warehousePlace = warehousePlace;
}
private String warehousePlace;//变量warehouseplace为String类型,表示存放商品的具体位置,长度八位数字XXXXYYZZ,其中XXXX表示货架号,YY表示货架的层号,ZZ表示存放在该货架该层的商品顺序号。
private int itemNumber;
private int outNumber;
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 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;
}
public WarehouseInformation(String itemNo, String itemName, String supplierName, String warehousingTime, String warehouseNumber, String warehousePlace, int itemNumber) {
this.itemNo = itemNo;
this.itemName = itemName;
this.supplierName = supplierName;
this.warehousingTime = warehousingTime;
this.warehouseNumber = warehouseNumber;
this.warehousePlace = warehousePlace;
this.itemNumber = itemNumber;
}
public WarehouseInformation(WarehouseInformation information) {
this.itemNo = information.getItemNo();
this.itemName = information.getItemName();
this.supplierName = information.getSupplierName();
this.warehousingTime = information.getWarehousingTime();
this.warehouseNumber = information.getWarehouseNumber();
this.warehousePlace = information.getWarehousePlace();
this.itemNumber = information.getItemNumber();
this.shipmentTime = information.getShipmentTime();
this.outNumber = information.getOutNumber();
}
public WarehouseInformation() {
}
}
功能类
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
public class WarehouseManagement {
private final ArrayList<WarehouseInformation> warehouseInformationList;
WarehouseManagement() {
warehouseInformationList = new ArrayList<>();
}
public void loadFile() {
try {
File file = new File("warehouseInformation.txt");
if (!file.exists()) {
file.createNewFile();
}
java.util.Scanner input = new java.util.Scanner(file);
while (input.hasNext()) {
WarehouseInformation information = new WarehouseInformation();
information.setItemNo(input.next());
information.setItemName(input.next());
information.setSupplierName(input.next());
information.setWarehousingTime(input.next());
information.setShipmentTime(input.next());
information.setWarehouseNumber(input.next());
information.setWarehousePlace(input.next());
information.setItemNumber(input.nextInt());
information.setOutNumber(input.nextInt());
warehouseInformationList.add(information);
}
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public WarehouseInformation getWarehouseInfo(String itemID) {
for (WarehouseInformation information : warehouseInformationList) {
if (information.getItemNo().equals(itemID)) {
return information;
}
}
return null;
}
public void removeWarehouseInfo(WarehouseInformation information) {
warehouseInformationList.remove(information);
}
public void warehousing(WarehouseInformation information) {
warehouseInformationList.add(information);
}
public void editItem(WarehouseInformation old_information, WarehouseInformation new_information) {
removeWarehouseInfo(old_information);
warehouseInformationList.add(new_information);
}
public ArrayList<WarehouseInformation> getWarehouseInformationList() {
return warehouseInformationList;
}
public void exitSystem(boolean isSave) throws IOException {
if (isSave) {
saveWarehouseInformation();
System.exit(0);
}
}
private void saveWarehouseInformation () throws IOException {
BufferedWriter out = new BufferedWriter(new FileWriter("warehouseInformation.txt"));
for (WarehouseInformation information : warehouseInformationList) {
out.write(information.getItemNo() + " " + information.getItemName() + " " + information.getSupplierName() + " " + information.getWarehousingTime() + " " + information.getShipmentTime() + " " + information.getWarehouseNumber() + " " + information.getWarehousePlace() + " " + information.getItemNumber() + " " + information.getOutNumber() + "\n");
}
out.close();
System.out.println("保存成功!");
}
}
界面类
import java.io.IOException;
import java.util.Scanner;
public class UserInterface {
String uiTitle = """
***********************************************************
石家庄铁道大学前进22软件开发有限公司
仓库管理系统2022版
***********************************************************
""";
String uiFooter = """
***********************************************************
""";
public void displayItemInfo(WarehouseInformation information) {
System.out.println("1.商品编号:" + information.getItemNo());
System.out.println("2.商品名称:" + information.getItemName());
System.out.println("3.供货商信息:" + information.getSupplierName());
System.out.println("4.入库时间:" + information.getWarehousingTime());
System.out.println("5.仓库编号:" + information.getWarehouseNumber());
System.out.println("6.存放位置信息:" + information.getWarehousePlace());
System.out.println("7.商品数量:" + (information.getItemNumber() - information.getOutNumber()));
}
public WarehouseInformation inputItemInfo() {
System.out.println("请输入商品编号:");
Scanner scanner = new Scanner(System.in);
String itemNo = scanner.next();
while (itemNo.length() != 8) {
System.out.println("商品编号长度错误,请重新输入");
itemNo = scanner.next();
}
System.out.println("请输入商品名称:");
String itemName = scanner.next();
System.out.println("请输入供货商信息");
String supplierName = scanner.next();
System.out.println("请输入入库时间");
String warehousingTime = scanner.next();
while (warehousingTime.length() != 8) {
System.out.println("入库时间格式错误,请重新输入");
warehousingTime = scanner.next();
}
System.out.println("请输入仓库编号");
String warehouseNumber = scanner.next();
while (warehouseNumber.length() != 3) {
System.out.println("仓库编号错误,请重新输入");
warehouseNumber = scanner.next();
}
System.out.println("请输入存放位置信息");
String warehousePlace = scanner.next();
while (warehousePlace.length() != 8) {
System.out.println("存放位置信息错误,请重新输入");
warehousePlace = scanner.next();
}
System.out.println("请输入商品数量");
if (!scanner.hasNextInt()) {
System.out.println("商品数量错误,请重新输入");
scanner.next();
}
int itemNumber = scanner.nextInt();
return new WarehouseInformation(itemNo,itemName,supplierName,warehousingTime,warehouseNumber,warehousePlace,itemNumber);
}
public void mainMenu(WarehouseManagement management) throws IOException {
while (true) {
System.out.println(uiTitle);
System.out.println("""
1、商品入库管理
2、商品信息修改
3、商品出库管理
4、仓库盘点管理
5、退出系统
***********************************************************
请选择:
""");
Scanner scanner = new Scanner(System.in);
while (!scanner.hasNextInt()) {
System.out.println("输入错误,请重试");
scanner.next();
}
if (scanner.hasNextInt()) {
int choice = scanner.nextInt();
switch (choice) {
case 1 -> warehousing(management);
case 2 -> editItem(management);
case 3 -> shipment(management);
case 4 -> inventory(management);
case 5 -> {
exitInterface(management);
return;
}
default -> {
System.out.println("输入错误,请重试");
}
}
}
}
}
private void exitInterface(WarehouseManagement management) throws IOException {
System.out.println(uiTitle);
System.out.println("是否保存修改后的信息?(Y/N)");
Scanner scanner = new Scanner(System.in);
String choice = scanner.next();
while (!choice.equals("Y") && !choice.equals("N")) {
System.out.println("输入错误,请重新输入");
choice = scanner.next();
}
if (choice.equals("Y")) {
management.exitSystem(true);
System.out.println("信息保存成功");
}
else {
management.exitSystem(false);
System.out.println("信息未保存");
}
}
private void inventory(WarehouseManagement management) {
System.out.println(uiTitle);
int count = 1;
for (WarehouseInformation information : management.getWarehouseInformationList()) {
System.out.println(count + "、商品编号:" + information.getItemNo() + ",商品名称:" + information.getItemName() + ",库存数量:" + (information.getItemNumber() - information.getOutNumber()));
count++;
}
System.out.println(uiFooter);
}
private void shipment(WarehouseManagement management) {
System.out.println(uiTitle);
System.out.println("请输入要出库的商品编号:");
Scanner scanner = new Scanner(System.in);
String itemNo = scanner.next();
while (itemNo.length() != 8) {
System.out.println("商品编号长度错误,请重新输入");
itemNo = scanner.next();
}
WarehouseInformation information = management.getWarehouseInfo(itemNo);
if (information == null) {
System.out.println("商品编号不存在!");
} else {
System.out.println("商品信息如下:");
displayItemInfo(information);
System.out.println("请输入出库时间:");
String shipmentTime = scanner.next();
if (shipmentTime.length() != 8) {
System.out.println("出库时间格式错误,请重新输入");
shipmentTime = scanner.next();
}
System.out.println("请输入出库数量:");
if (!scanner.hasNextInt()) {
System.out.println("出库数量错误,请重新输入");
scanner.next();
}
if (scanner.hasNextInt()) {
int outNumber = scanner.nextInt();
if (outNumber > information.getItemNumber() - information.getOutNumber()) {
System.out.println("出库数量大于库存数量,出库失败");
}
else {
System.out.println("出库操作已完成,是否提交(Y/N)");
String choice = scanner.next();
while (!choice.equals("Y") && !choice.equals("N")) {
System.out.println("输入错误,请重新输入");
choice = scanner.next();
}
if (choice.equals("Y")
) {
System.out.println("出库操作已提交");
information.setOutNumber(outNumber + information.getOutNumber());
information.setShipmentTime(shipmentTime);
management.removeWarehouseInfo(information);
management.warehousing(information);
System.out.println("出库操作已完成");
}
else {
System.out.println("出库操作已取消");
}
}
}
}
System.out.println(uiFooter);
}
private void editItem(WarehouseManagement management) {
System.out.println(uiTitle);
System.out.println("请输入要修改的商品编号:");
Scanner scanner = new Scanner(System.in);
String itemNo = scanner.next();
while (itemNo.length() != 8) {
System.out.println("商品编号长度错误,请重新输入");
itemNo = scanner.next();
}
WarehouseInformation information = management.getWarehouseInfo(itemNo);
if (information == null) {
System.out.println("商品编号不存在!");
editItem(management);
} else {
System.out.println("商品信息如下:");
displayItemInfo(information);
System.out.println("请选择要修改的信息:(1~7)");
while (!scanner.hasNextInt()) {
System.out.println("输入错误,请重试");
scanner.next();
}
WarehouseInformation new_information = new WarehouseInformation(information);
int choice = scanner.nextInt();
switch (choice) {
case 1 -> {
System.out.println("请输入新的商品编号:");
String newItemNo = scanner.next();
while (newItemNo.length() != 8) {
System.out.println("商品编号长度错误,请重新输入");
newItemNo = scanner.next();
}
new_information.setItemNo(newItemNo);
}
case 2 -> {
System.out.println("请输入新的商品名称:");
String newItemName = scanner.next();
new_information.setItemName(newItemName);
}
case 3 -> {
System.out.println("请输入新的供货商信息:");
String newSupplierName = scanner.next();
new_information.setSupplierName(newSupplierName);
}
case 4 -> {
System.out.println("请输入新的入库时间:");
String newWarehousingTime = scanner.next();
while (newWarehousingTime.length() != 8) {
System.out.println("入库时间格式错误,请重新输入");
newWarehousingTime = scanner.next();
}
new_information.setWarehousingTime(newWarehousingTime);
}
case 5 -> {
System.out.println("请输入新的仓库编号:");
String newWarehouseNumber = scanner.next();
while (newWarehouseNumber.length() != 3) {
System.out.println("仓库编号错误,请重新输入");
newWarehouseNumber = scanner.next();
}
new_information.setWarehouseNumber(newWarehouseNumber);
}
case 6 -> {
System.out.println("请输入新的存放位置信息:");
String newWarehousePlace = scanner.next();
while (newWarehousePlace.length() != 8) {
System.out.println("存放位置信息错误,请重新输入");
newWarehousePlace = scanner.next();
}
new_information.setWarehousePlace(newWarehousePlace);
}
case 7 -> {
System.out.println("请输入新的商品数量:");
if (!scanner.hasNextInt()) {
System.out.println("商品数量错误,请重新输入");
scanner.next();
}
int newItemNumber = scanner.nextInt();
new_information.setItemNumber(newItemNumber);
}
default -> System.out.println("该选项不存在");
}
System.out.println("要保存修改后的信息吗?(Y/N)");
String choice2 = scanner.next();
while (!choice2.equals("Y") && !choice2.equals("N")) {
System.out.println("输入错误,请重新输入");
choice2 = scanner.next();
}
if (choice2.equals("Y")) {
management.editItem(information,new_information);
System.out.println("商品信息修改已提交");
}
else {
System.out.println("商品信息修改已取消");
}
}
System.out.println(uiFooter);
}
private void warehousing(WarehouseManagement management) {
System.out.println(uiTitle);
WarehouseInformation information = inputItemInfo();
displayItemInfo(information);
System.out.println("该商品入库操作已完成,是否提交(Y/N)");
Scanner scanner = new Scanner(System.in);
String choice = scanner.next();
while (!choice.equals("Y") && !choice.equals("N")) {
System.out.println("输入错误,请重新输入");
choice = scanner.next();
}
if (choice.equals("Y")) {
management.warehousing(information);
System.out.println("商品入库操作已提交");
}
else {
System.out.println("商品入库操作已取消");
}
System.out.println(uiFooter);
}
}
主函数类
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
WarehouseManagement management = new WarehouseManagement();
UserInterface ui = new UserInterface();
ui.mainMenu(management);
}
}