/* * . Accept a flat file as input + 1. Each line will contain the amount owed and the amount paid separated by a comma (for example: 2.13,3.00) + 2. Expect that there will be multiple lines */ public string ProcessAmounts(TransactionAmounts transactionAmounts) { string str; AbsTranslator translator; decimal d = new CashRegister().CalculateChange(transactionAmounts); if (d > 0) { if ((d % 3) == 0) { translator = new TranslatorFactory().GetTranslator(MoneyConstants.RandomUSD); str = translator.TranslateAmount(d); } else { translator = new TranslatorFactory().GetTranslator(MoneyConstants.USD); str = translator.TranslateAmount(d); } } else if (d == 0) { str = "You have paid the exact amount"; } else { translator = new TranslatorFactory().GetTranslator(MoneyConstants.USD); str = "You still owe "+translator.TranslateAmount(Math.Abs(d)); } return str; }
public List<TransactionAmounts> HandleInput(string infile) { var list = new List<TransactionAmounts>(); using (var rd = new StreamReader(infile)) { while (!rd.EndOfStream) { var splits = rd.ReadLine().Split(','); var ta = new TransactionAmounts { AmountOwed = decimal.Parse(splits[0]), AmountPaid = decimal.Parse(splits[1]) }; list.Add(ta); } } return list; }
/* 2. Output the change the cashier should return to the customer + 1. The return string should look like: 1 dollar,2 quarters,1 nickel, etc ... + 2. Each new line in the input file should be a new line in the output file */ public decimal CalculateChange(TransactionAmounts transAmounts) { decimal difference = transAmounts.AmountPaid - transAmounts.AmountOwed; return difference; }