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

📄 invertory.java

📁 点菜系统
💻 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("0002","宫保鸡丁",2.30,15));
add(new InventoryItem("0003","宫保鸡丁",2.30,15));
add(new InventoryItem("0004","宫保鸡丁",2.30,15));
}

//根据用户输入的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_MASSAGE);
}
//在存货清单中,根据用户输入的id和用户输入的数量。
//减少相应商品的数量
public void addUnits (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_MASSAGE);
}
}

⌨️ 快捷键说明

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