/// <summary> /// removes banknotes from the ATM /// called only after a successfull withdraw operation /// </summary> /// <param name="banknotes">BanknoteContainer containing BanknoteCount objects with the number of /// banknotes to remove from the ATM</param> private void RemoveBanknotes(BanknoteContainer banknotes) { for (int i = 0; i < banknotes.Count; i++) { Banknote banknote = banknotes.GetBanknote(i); int banknoteIndex = Banknotes.BanknoteIndex(banknote); Banknotes.InsertBanknote(banknoteIndex, (Banknotes.GetBanknote(banknoteIndex) as BanknoteCount) - (banknote as BanknoteCount)); } }
/// <summary> /// gets the index in the container of a given banknote /// </summary> /// <param name="banknote">Banknote to check for</param> /// <returns>the index of the given Banknote, -1 if the banknote was not found in the container</returns> public int BanknoteIndex(Banknote banknote) { for (int i = 0; i < Count; i++) { if (Banknotes[i] == banknote) { return(i); } } return(-1); }
/// <summary> /// inserts a banknote at a given index /// </summary> /// <param name="index">index to insert banknote to</param> /// <param name="banknote">Banknote to insert</param> public void InsertBanknote(int index, Banknote banknote) { Banknotes[index] = banknote; }
/// <summary> /// adds a banknote to the end of the container /// </summary> /// <param name="banknote">Banknote to add</param> public void AddBanknote(Banknote banknote) { Banknotes[Count++] = banknote; }