/** * 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); }
/** * 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 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; }