/// <summary> /// creates BanknoteCount object for each banknote in the data arrays /// /// EXAMPLE DATA ARRAYS: /// banknoteType: ["500", "200", "100"] /// banknoteCount: ["10", "7", "15"] /// this means there are 10 banknotes worth 500, 7 banknotes worth 200 and 15 banknotes worth 100 /// </summary> /// <param name="banknoteType">array containing banknote wealth values</param> /// <param name="banknoteCount">array containing banknote count values</param> /// <param name="banknotes">BanknoteContainer to store created BanknoteCount objects in</param> static void CreateBankotes(string[] banknoteType, string[] banknoteCount, BanknoteContainer banknotes) { for (int i = 0; i < NumberOfBanknoteTypes; i++) { banknotes.AddBanknote(new BanknoteCount(int.Parse(banknoteType[i]), int.Parse(banknoteCount[i]))); } }
/// <summary> /// tries to get enough right banknotes for a withdraw operation /// this method does not remove any banknotes from the ATM, it only creates copies of the banknotes /// to withdraw /// </summary> /// <param name="ammount">ammount of money to withdraw</param> /// <param name="success">boolean indicating wether there was enough right banknotes to withdraw</param> /// <returns>BanknoteContainer of banknotes to be withdrawn (will be used only is success = true)</returns> private BanknoteContainer GetBanknotes(int ammount, out bool success) { BanknoteContainer banknotes = new BanknoteContainer(Program.NumberOfBanknoteTypes); for (int i = 0; i < Banknotes.Count; i++) { BanknoteCount banknote = Banknotes.GetBanknote(i) as BanknoteCount; int numberOfBanknotesRequired = ammount / banknote.Wealth; int availableBanknotes = (banknote.Count >= numberOfBanknotesRequired) ? numberOfBanknotesRequired : banknote.Count; banknotes.AddBanknote(new BanknoteCount(banknote.Wealth, availableBanknotes)); ammount -= availableBanknotes * banknote.Wealth; } success = ammount == 0; return(banknotes); }