?? invertory.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 + -