/// <summary> /// loops through all Banknote objects in a BanknoteContainer and writes formatted banknote strings to /// a StreamWriter /// </summary> /// <param name="writer">StreamWriter to write to</param> /// <param name="banknotes">BanknoteContainer containing banknotes to print</param> static void PrintBanknotes(StreamWriter writer, BanknoteContainer banknotes) { for (int i = 0; i < banknotes.Count; i++) { writer.WriteLine("{0}", banknotes.GetBanknote(i).ToString()); } }
/// <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> /// calculates the ammount of money in BanknoteContainer /// </summary> /// <param name="banknotes">BanknoteContainer to take data from</param> /// <returns>the ammount of money from the banknotes</returns> public int CalculateMoney(BanknoteContainer banknotes) { int ammount = 0; for (int i = 0; i < banknotes.Count; i++) { BanknoteCount banknote = banknotes.GetBanknote(i) as BanknoteCount; ammount += banknote.Count * banknote.Wealth; } return(ammount); }
/// <summary> /// creates information string from a successfull withdraw operation: /// client's bank account number, banknotes the client just received and the ammount of money client has left /// </summary> /// <param name="client">Client who performed withdraw operation</param> /// <param name="banknotes">banknotes the client received from the ATM</param> /// <returns>formatted withdrawing operation text</returns> private string FormSuccessfullWithdrawingOperationString(Client client, BanknoteContainer banknotes) { string operation = string.Format("{0} {1}", client.BankAccountNumber, client.CurrentAmmount + CalculateMoney(banknotes), client.AmmountToWithdraw); for (int i = 0; i < banknotes.Count; i++) { BanknoteCount banknote = banknotes.GetBanknote(i) as BanknoteCount; operation = string.Format("{0}-{1}*{2}", operation, banknote.Wealth, banknote.Count); } operation = string.Format("{0} = {1}", operation, client.CurrentAmmount); return(operation); }