用java实现一个仓库管理系统
时间: 2023-05-19 09:02:24 浏览: 113
基于java的仓库管理系统
4星 · 用户满意度95%
好的,仓库管理系统可以包含以下功能:添加商品、删除商品、修改商品信息、查询商品信息、入库、出库、库存盘点等。以下是一个简单的Java代码示例,可以作为仓库管理系统的基础:
```
import java.util.ArrayList;
import java.util.Scanner;
public class WarehouseManagementSystem {
private ArrayList<Product> products;
public WarehouseManagementSystem() {
products = new ArrayList<>();
}
public void addProduct(Product product) {
products.add(product);
}
public void removeProduct(int index) {
products.remove(index);
}
public void updateProduct(int index, Product product) {
products.set(index, product);
}
public Product getProduct(int index) {
return products.get(index);
}
public ArrayList<Product> getAllProducts() {
return products;
}
public int getProductCount() {
return products.size();
}
public static void main(String[] args) {
WarehouseManagementSystem wms = new WarehouseManagementSystem();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请选择操作:");
System.out.println("1. 添加商品");
System.out.println("2. 删除商品");
System.out.println("3. 修改商品信息");
System.out.println("4. 查询商品信息");
System.out.println("5. 入库");
System.out.println("6. 出库");
System.out.println("7. 库存盘点");
System.out.println("0. 退出");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
System.out.println("请输入商品名称:");
String name = scanner.nextLine();
System.out.println("请输入商品数量:");
int quantity = scanner.nextInt();
scanner.nextLine();
Product product = new Product(name, quantity);
wms.addProduct(product);
System.out.println("添加成功!");
break;
case 2:
System.out.println("请输入要删除的商品编号:");
int index = scanner.nextInt();
scanner.nextLine();
wms.removeProduct(index);
System.out.println("删除成功!");
break;
case 3:
System.out.println("请输入要修改的商品编号:");
int index2 = scanner.nextInt();
scanner.nextLine();
System.out.println("请输入新的商品名称:");
String name2 = scanner.nextLine();
System.out.println("请输入新的商品数量:");
int quantity2 = scanner.nextInt();
scanner.nextLine();
Product product2 = new Product(name2, quantity2);
wms.updateProduct(index2, product2);
System.out.println("修改成功!");
break;
case 4:
System.out.println("请输入要查询的商品编号:");
int index3 = scanner.nextInt();
scanner.nextLine();
Product product3 = wms.getProduct(index3);
System.out.println("商品名称:" + product3.getName());
System.out.println("商品数量:" + product3.getQuantity());
break;
case 5:
System.out.println("请输入要入库的商品编号:");
int index4 = scanner.nextInt();
scanner.nextLine();
System.out.println("请输入入库数量:");
int quantity4 = scanner.nextInt();
scanner.nextLine();
Product product4 = wms.getProduct(index4);
product4.setQuantity(product4.getQuantity() + quantity4);
System.out.println("入库成功!");
break;
case 6:
System.out.println("请输入要出库的商品编号:");
int index5 = scanner.nextInt();
scanner.nextLine();
System.out.println("请输入出库数量:");
int quantity5 = scanner.nextInt();
scanner.nextLine();
Product product5 = wms.getProduct(index5);
if (product5.getQuantity() < quantity5) {
System.out.println("库存不足!");
} else {
product5.setQuantity(product5.getQuantity() - quantity5);
System.out.println("出库成功!");
}
break;
case 7:
System.out.println("当前库存:");
for (int i = 0; i < wms.getProductCount(); i++) {
Product product6 = wms.getProduct(i);
System.out.println("商品编号:" + i);
System.out.println("商品名称:" + product6.getName());
System.out.println("商品数量:" + product6.getQuantity());
}
break;
case 0:
System.out.println("谢谢使用!");
System.exit(0);
break;
default:
System.out.println("输入有误,请重新输入!");
break;
}
}
}
}
class Product {
private String name;
private int quantity;
public Product(String name, int quantity) {
this.name = name;
this.quantity = quantity;
}
public String getName() {
return name;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
}
```
阅读全文