以下是一个使用Java编写的高效超市进销存管理系统的基本框架。该系统包括商品管理、库存管理、销售管理和报表生成等功能。
```java
import java.util.*;
class Product {
String name;
double price;
int quantity;
public Product(String name, double price, int quantity) {
this.name = name;
this.price = price;
this.quantity = quantity;
}
}
class Inventory {
List
public Inventory() {
products = new ArrayList<>();
}
public void addProduct(Product product) {
products.add(product);
}
public void removeProduct(Product product) {
products.remove(product);
}
public List
return products;
}
}
class Sales {
Map
public Sales() {
sales = new HashMap<>();
}
public void addSales(String productName, int quantity) {
sales.put(productName, sales.getOrDefault(productName, 0) + quantity);
}
public void removeSales(String productName, int quantity) {
- sales.put(productName, sales.getOrDefault(productName, 0)
- quantity);
}
public Map
return sales;
}
}
class Report {
Map
Map
public Report() {
totalSales = new HashMap<>();
totalQuantity = new HashMap<>();
}
public void addTotalSales(String productName, int quantity) {
totalSales.put(productName, totalSales.getOrDefault(productName, 0) + quantity);
}
public void addTotalQuantity(String productName, int quantity) {
totalQuantity.put(productName, totalQuantity.getOrDefault(productName, 0) + quantity);
}
public Map
return totalSales;
}
public Map
return totalQuantity;
}
}
public class SupermarketInventorySystem {
private Inventory inventory;
private Sales sales;
private Report report;
public SupermarketInventorySystem() {
inventory = new Inventory();
sales = new Sales();
report = new Report();
}
public void addProduct(String name, double price, int quantity) {
inventory.addProduct(new Product(name, price, quantity));
sales.addSales("" + name, quantity);
report.addTotalSales("" + name, quantity);
}
public void removeProduct(String name) {
inventory.removeProduct(new Product("" + name, "", 0));
sales.removeSales("" + name, 0);
report.addTotalQuantity("" + name, 0);
}
public void printReport() {
System.out.println("Total Sales: " + report.getTotalSales());
System.out.println("Total Quantity: " + report.getTotalQuantity());
}
}
```
这个系统使用了三个类:`Product`用于表示商品,`Inventory`用于表示库存,`Sales`用于表示销售,`Report`用于表示报表。在主类`SupermarketInventorySystem`中,我们创建了这三个类的对象,并实现了添加商品、删除商品、打印报表等方法。