给我找一份仓库管理系统的的代码
时间: 2024-04-06 14:32:24 浏览: 10
由于仓库管理系统的复杂程度和功能需求不同,所以具体的代码实现可能会有所不同。以下是一个简单的仓库管理系统的Java代码示例,仅供参考:
```java
import java.util.ArrayList;
import java.util.List;
public class WarehouseManagementSystem {
public static void main(String[] args) {
List<Product> products = new ArrayList<>();
products.add(new Product("p001", "Product 1", 10, 5));
products.add(new Product("p002", "Product 2", 20, 10));
products.add(new Product("p003", "Product 3", 30, 15));
Warehouse warehouse = new Warehouse(products);
System.out.println("Initial stock:");
warehouse.printStock();
// Perform some stock movements
warehouse.receiveStock("p001", 5);
warehouse.receiveStock("p002", 10);
warehouse.dispatchStock("p001", 2);
warehouse.dispatchStock("p003", 5);
System.out.println("Current stock:");
warehouse.printStock();
}
}
class Product {
private String id;
private String name;
private int quantity;
private double price;
public Product(String id, String name, int quantity, double price) {
this.id = id;
this.name = name;
this.quantity = quantity;
this.price = price;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public int getQuantity() {
return quantity;
}
public double getPrice() {
return price;
}
}
class Warehouse {
private List<Product> products;
public Warehouse(List<Product> products) {
this.products = products;
}
public void receiveStock(String productId, int quantity) {
for (Product product : products) {
if (product.getId().equals(productId)) {
product.quantity += quantity;
System.out.println("Received " + quantity + " units of " + product.getName());
return;
}
}
System.out.println("Product with ID " + productId + " not found");
}
public void dispatchStock(String productId, int quantity) {
for (Product product : products) {
if (product.getId().equals(productId)) {
if (product.quantity < quantity) {
System.out.println("Insufficient stock for " + product.getName());
return;
}
product.quantity -= quantity;
System.out.println("Dispatched " + quantity + " units of " + product.getName());
return;
}
}
System.out.println("Product with ID " + productId + " not found");
}
public void printStock() {
for (Product product : products) {
System.out.println(product.getId() + "\t" + product.getName() + "\t" + product.getQuantity());
}
}
}
```
以上代码实现了一个简单的仓库管理系统,可以对库存进行进货和出货操作,并且可以打印当前库存情况。请注意,这只是一个示例,实际的仓库管理系统需要根据具体的业务需求进行设计和实现。