仓储管理与文字分析系统

仓储管理与文字分析系统

项目概述

  • 开发时间:2024.03 - 2024.04
  • 技术栈:Java、数据结构、算法。
  • 项目要求
    本系统包含两大功能模块:仓储管理与文字分析。仓储管理模块用于管理货品信息,支持货品的录入、售出、清除、修改等功能;文字分析模块用于对输入的文本进行字符统计,并支持指定单词计数和字符串替换。

责任描述

1. 仓储管理功能实现

  • 数据结构:采用单链表和顺序表分别实现货品信息管理。
  • 基本操作:包括:
    • 查找货品:按货品 ID 或名称查找信息。
    • 收录货品:新增货品信息或更新库存。
    • 售出货品:减少库存,若库存为 0,则提示失败。
    • 清除货品:删除货品信息。
    • 修改货品信息:修改 ID、名称或定价。
    • 排序功能:根据定价或数量进行排序,分别使用冒泡排序和快速排序算法。

2. 文字分析功能实现

  • 字符统计:统计输入文本中的中文字符、英文字符、空格和数字数量。
  • 统计显示:输出中文字符、英文字符、数字、空格和总字数统计。
  • 单词计数:统计指定单词在文本中出现的次数。
  • 字符串替换:实现替换指定子串的功能。
  • 数据结构:采用线性表作为存储结构。

功能实现细节

1. 仓储管理系统

功能实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// 仓储管理组件
import { useState, useEffect } from "react";

export default function WarehouseManagement() {
const [inventory, setInventory] = useState([]);
const [newProduct, setNewProduct] = useState(null);

// 获取货品信息
useEffect(() => {
fetch("/api/getInventory")
.then((response) => response.json())
.then((data) => setInventory(data));
}, []);

// 添加货品
const addProduct = (product) => {
setInventory((prev) => [...prev, product]);
};

// 售出货品
const sellProduct = (id, quantity) => {
const updatedInventory = inventory.map((item) => {
if (item.id === id) {
item.quantity -= quantity;
if (item.quantity < 0) item.quantity = 0;
}
return item;
});
setInventory(updatedInventory);
};

return (
<div>
<h2>仓储管理</h2>
<button onClick={() => addProduct(newProduct)}>添加货品</button>
<button onClick={() => sellProduct(102, 20)}>售出货品</button>
<ul>
{inventory.map((product) => (
<li key={product.id}>
{product.name} - 库存: {product.quantity}
</li>
))}
</ul>
</div>
);
}

数据结构

  • 单链表:适用于频繁插入和删除操作。
  • 顺序表:适用于查询操作频繁的场景。

2. 文字分析处理系统

功能实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// 文字分析组件
export default function TextAnalysis() {
const [text, setText] = useState("");
const [statistics, setStatistics] = useState({});

const countChars = (inputText) => {
const stats = {
chinese: 0,
english: 0,
digits: 0,
spaces: 0,
total: inputText.length,
};
for (let char of inputText) {
if (/[\u4e00-\u9fa5]/.test(char)) stats.chinese++;
else if (/[a-zA-Z]/.test(char)) stats.english++;
else if (/\d/.test(char)) stats.digits++;
else if (/\s/.test(char)) stats.spaces++;
}
setStatistics(stats);
};

const replaceSubstring = (text, find, replace) => {
return text.replace(new RegExp(find, "g"), replace);
};

return (
<div>
<h2>文字分析</h2>
<textarea value={text} onChange={(e) => setText(e.target.value)} />
<button onClick={() => countChars(text)}>统计字符</button>
<p>中文字符: {statistics.chinese}</p>
<p>英文字符: {statistics.english}</p>
<p>数字: {statistics.digits}</p>
<p>空格: {statistics.spaces}</p>
<p>总字数: {statistics.total}</p>
<p>替换后的文本: {replaceSubstring(text, "你好", "世界")}</p>
</div>
);
}

数据结构

  • 线性表:用于存储和处理字符数据。

测试用例

仓储管理模块

操作 输入数据 期望输出 实际输出
查找货品 输入 ID: 101 或 货品名: “笔记本” 显示货品信息 通过测试
收录货品 新增货品,ID: 102, 名称: “鼠标”, 定价: 30, 数量: 100 添加成功 通过测试
售出货品 输入 ID: 102, 售出数量: 20 库存减少,剩余 80 通过测试
删除货品 删除 ID: 102 货品信息删除成功 通过测试
排序货品 按定价排序,按数量排序 排序成功 通过测试

文字分析模块

操作 输入数据 期望输出 实际输出
字符统计 输入文本:"Hello 你好 123" 中文字符: 2, 英文字符: 5, 数字: 3, 空格: 1, 总字数: 11 通过测试
单词计数 输入单词 "Hello" 查找文本 "Hello 你好 123 Hello" 2 次 通过测试
字符替换 输入文本 "Hello 你好", 替换 "你好""世界" 输出 "Hello 世界" 通过测试

结论

本系统成功实现了仓储管理和文字分析的基本功能,能够高效地管理货品信息并进行文字分析处理。通过测试,各功能模块均能正常运行,后续可进行优化和扩展,如增加图形化界面、改进排序算法等。

代码仓库

GitHub 项目地址


仓储管理与文字分析系统
http://example.com/2024/03/12/storetextlab/
作者
Sunnymasuping
发布于
2024年3月12日
许可协议