⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inventory.java

📁 商品库存管理系统JAVA程序,不需要数据库.很小源程序可使用Jdk1.3以上的任何版本编译和运行
💻 JAVA
字号:
package chapter1;

import javax.swing.JOptionPane;

public class Inventory extends SortedList {
	//存货清单构造函数
	public Inventory() {
		super(4, new ItemComparer());
		add(new InventoryItem("0001", "电池", 2.30, 15));
		add(new InventoryItem("2002", "彩电", 1280.00, 10));
		add(new InventoryItem("0015", "电扇", 128.00, 10));
		add(new InventoryItem("3009", "台灯", 32.00, 20));

	}

	//根据用户输入的id,返回相应的存货条目,不存在的话,返回null
	public InventoryItem getPart(String _id) {
		int index = indexOf(new Item(_id));
		if (index >= 0)
			return (InventoryItem) get(index);
		else
			return null;
	}

	//在存货清单中,根据用户输入的id和用户输入的数量,增加相应货物的数量
	public void addUnits(String _id, int _number) {
		InventoryItem item = getPart(_id);
		if (item != null)
			item.add(_number);
		else
			JOptionPane.showMessageDialog(null, "没有找到和输入ID对应的项!", "警告",
					JOptionPane.ERROR_MESSAGE);
	}

	//在存货清单中,根据用户输入的id和用户输入的数量,减少相应货物的数量
	public void removeUnits(String _id, int _number) {
		InventoryItem item = getPart(_id);
		if ((item != null) && (item.units >= _number) && (_number >= 0))
			item.remove(_number);
		else
			JOptionPane.showMessageDialog(null, "没有找到和输入ID对应的项或空间不足!", "警告",
					JOptionPane.ERROR_MESSAGE);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -