/** * add an item to the reciept and its price to the bill * * newItem the food item to add */ public void addItem(FoodItem newItem) { if(iNumItems >= itemsBought.Length) { return; } fBill += newItem.getPrice(); itemsBought[iNumItems] = new FoodItem(newItem.getName(), newItem.getPrice(), newItem.getTime()); itemsBought[iNumItems].setAmountSold(1); iNumItems++; this.updateTotalItemBought(newItem); }
public void undoBuy(FoodItem item, int undo) { for(int i = 0; i < items.Length; i++) { if (items[i].getName().Equals(item.getName())) { items[i].undoSold(undo); } } }
/** * searches and removes one instance of a food item with the name of the given item * * returns 0 if successful * returns 1 in nothing removed */ public int removeItem(FoodItem item) { fBill -= item.getPrice(); for(int i = 0; i < itemsBought.Length; i++) { if(itemsBought[i] != null && itemsBought[i].getName().Equals(item.getName())) { itemsBought[i] = null; return 0; } } return 1; }
/** * searches and updates one common item to have a total count of the number sold * * returns 0 if successful * returns 1 in nothing removed */ public void updateTotalItemBought(FoodItem item) { for (int i = 0; i < itemsBought.Length; i++) { if (itemsBought[i] != null && itemsBought[i].getName().Equals(item.getName())) { itemsBought[i].setAmountSold(itemsBought[i].getSold() + 1); return; } } }
/** * searches and removes one instance of a food item with the name of the given item * * returns 0 if successful * returns 1 in nothing removed */ public int removeAllItem(FoodItem item) { fBill -= item.getPrice(); int i = 0; ArrayList temp = new ArrayList(); foreach (FoodItem list in itemsBought) { if (list != null && list.getName().Equals(item.getName())) { list.setAmountSold(0); } } return 1; }