用java写一个仓库管理系统
时间: 2023-12-29 08:06:47 浏览: 64
好的,仓库管理系统可以包括以下功能:
1. 商品管理:添加、删除、修改商品信息。
2. 入库管理:记录商品入库信息,包括商品名称、数量、价格等信息。
3. 出库管理:记录商品出库信息,包括商品名称、数量、价格等信息。
4. 库存查询:查询商品当前库存数量及价格。
5. 统计报表:统计商品入库、出库、库存等信息,生成报表。
下面是一个简单的仓库管理系统的 Java 代码实现:
```java
import java.util.ArrayList;
import java.util.Scanner;
public class WarehouseManagementSystem {
static ArrayList<Commodity> commodities = new ArrayList<Commodity>();
static ArrayList<InRecord> inRecords = new ArrayList<InRecord>();
static ArrayList<OutRecord> outRecords = new ArrayList<OutRecord>();
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请选择操作:1.商品管理 2.入库管理 3.出库管理 4.库存查询 5.统计报表 6.退出");
int choice = scanner.nextInt();
switch (choice) {
case 1:
commodityManagement(scanner);
break;
case 2:
inManagement(scanner);
break;
case 3:
outManagement(scanner);
break;
case 4:
queryInventory(scanner);
break;
case 5:
statisticsReport();
break;
case 6:
System.exit(0);
break;
default:
System.out.println("输入有误,请重新输入!");
break;
}
}
}
// 商品管理
public static void commodityManagement(Scanner scanner) {
while (true) {
System.out.println("请选择操作:1.添加商品 2.删除商品 3.修改商品 4.返回上一级");
int choice = scanner.nextInt();
switch (choice) {
case 1:
addCommodity(scanner);
break;
case 2:
deleteCommodity(scanner);
break;
case 3:
modifyCommodity(scanner);
break;
case 4:
return;
default:
System.out.println("输入有误,请重新输入!");
break;
}
}
}
// 添加商品
public static void addCommodity(Scanner scanner) {
System.out.println("请输入商品名称:");
String name = scanner.next();
System.out.println("请输入商品单价:");
double price = scanner.nextDouble();
System.out.println("请输入商品库存数量:");
int amount = scanner.nextInt();
Commodity commodity = new Commodity(name, price, amount);
commodities.add(commodity);
System.out.println("添加成功!");
}
// 删除商品
public static void deleteCommodity(Scanner scanner) {
System.out.println("请输入要删除的商品名称:");
String name = scanner.next();
for (int i = 0; i < commodities.size(); i++) {
if (commodities.get(i).getName().equals(name)) {
commodities.remove(i);
System.out.println("删除成功!");
return;
}
}
System.out.println("未找到该商品!");
}
// 修改商品
public static void modifyCommodity(Scanner scanner) {
System.out.println("请输入要修改的商品名称:");
String name = scanner.next();
for (int i = 0; i < commodities.size(); i++) {
if (commodities.get(i).getName().equals(name)) {
System.out.println("请输入修改后的商品单价:");
double price = scanner.nextDouble();
System.out.println("请输入修改后的商品库存数量:");
int amount = scanner.nextInt();
commodities.get(i).setPrice(price);
commodities.get(i).setAmount(amount);
System.out.println("修改成功!");
return;
}
}
System.out.println("未找到该商品!");
}
// 入库管理
public static void inManagement(Scanner scanner) {
System.out.println("请输入入库商品名称:");
String name = scanner.next();
System.out.println("请输入入库数量:");
int amount = scanner.nextInt();
System.out.println("请输入入库单价:");
double price = scanner.nextDouble();
InRecord inRecord = new InRecord(name, amount, price);
inRecords.add(inRecord);
for (int i = 0; i < commodities.size(); i++) {
if (commodities.get(i).getName().equals(name)) {
commodities.get(i).setAmount(commodities.get(i).getAmount() + amount);
return;
}
}
Commodity commodity = new Commodity(name, price, amount);
commodities.add(commodity);
}
// 出库管理
public static void outManagement(Scanner scanner) {
System.out.println("请输入出库商品名称:");
String name = scanner.next();
System.out.println("请输入出库数量:");
int amount = scanner.nextInt();
System.out.println("请输入出库单价:");
double price = scanner.nextDouble();
OutRecord outRecord = new OutRecord(name, amount, price);
outRecords.add(outRecord);
for (int i = 0; i < commodities.size(); i++) {
if (commodities.get(i).getName().equals(name)) {
if (commodities.get(i).getAmount() < amount) {
System.out.println("库存不足,无法出库!");
return;
}
commodities.get(i).setAmount(commodities.get(i).getAmount() - amount);
return;
}
}
System.out.println("未找到该商品!");
}
// 库存查询
public static void queryInventory(Scanner scanner) {
System.out.println("请输入要查询的商品名称:");
String name = scanner.next();
for (int i = 0; i < commodities.size(); i++) {
if (commodities.get(i).getName().equals(name)) {
System.out.println("商品名称:" + commodities.get(i).getName() + ",库存数量:" + commodities.get(i).getAmount() + ",单价:" + commodities.get(i).getPrice());
return;
}
}
System.out.println("未找到该商品!");
}
// 统计报表
public static void statisticsReport() {
double inTotal = 0, outTotal = 0, inventoryTotal = 0;
System.out.println("商品名称\t入库数量\t入库单价\t入库总价\t出库数量\t出库单价\t出库总价\t库存数量\t库存总价");
for (Commodity commodity : commodities) {
int inAmount = 0, outAmount = 0;
double inPrice = 0, outPrice = 0, inventoryPrice = 0;
for (InRecord inRecord : inRecords) {
if (inRecord.getName().equals(commodity.getName())) {
inAmount += inRecord.getAmount();
inPrice = inRecord.getPrice();
}
}
for (OutRecord outRecord : outRecords) {
if (outRecord.getName().equals(commodity.getName())) {
outAmount += outRecord.getAmount();
outPrice = outRecord.getPrice();
}
}
inventoryPrice = commodity.getAmount() * commodity.getPrice();
System.out.println(commodity.getName() + "\t" + inAmount + "\t" + inPrice + "\t" + inAmount * inPrice + "\t" + outAmount + "\t" + outPrice + "\t" + outAmount * outPrice + "\t" + commodity.getAmount() + "\t" + inventoryPrice);
inTotal += inAmount * inPrice;
outTotal += outAmount * outPrice;
inventoryTotal += inventoryPrice;
}
System.out.println("入库总额:" + inTotal + ",出库总额:" + outTotal + ",库存总额:" + inventoryTotal);
}
}
class Commodity {
private String name;
private double price;
private int amount;
public Commodity(String name, double price, int amount) {
this.name = name;
this.price = price;
this.amount = amount;
}
public String getName() {
return name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
}
class InRecord {
private String name;
private int amount;
private double price;
public InRecord(String name, int amount, double price) {
this.name = name;
this.amount = amount;
this.price = price;
}
public String getName() {
return name;
}
public int getAmount() {
return amount;
}
public double getPrice() {
return price;
}
}
class OutRecord {
private String name;
private int amount;
private double price;
public OutRecord(String name, int amount, double price) {
this.name = name;
this.amount = amount;
this.price = price;
}
public String getName() {
return name;
}
public int getAmount() {
return amount;
}
public double getPrice() {
return price;
}
}
```
以上代码只是一个简单的示例,实际应用中可能需要根据具体需求进行更改和扩展。
阅读全文