//CashValueList CashValueList; //public CashValueListParser(CashValueList cvl) //{ // CashValueList = cvl; //} public static CashValueWithCount ParseCashString(string paymentString, CashValueList CVL) { if (!paymentString.Contains("x") || !paymentString.EndsWith("kr")) { return(null); } var xIndex = paymentString.IndexOf("x"); var countString = paymentString.Substring(0, xIndex); var isSuccessCount = int.TryParse(countString, out int count); if (!isSuccessCount) { return(null); } var cashItemString = paymentString.Substring(xIndex + 1).TrimEnd('k', 'r'); var isSuccessCashItem = int.TryParse(cashItemString, out int cashItem); if (!isSuccessCashItem) { return(null); } var cashValue = CVL.FirstOrDefault(cashItem); if (cashValue == null) { return(null); } return(new CashValueWithCount(cashValue, count)); }
public static void Run() { CashValueList premadeCashValueList = new CashValueList(); PaymentHandler paymentHandler = new PaymentHandler(premadeCashValueList.GetSetCashValueList()); Console.WriteLine("Hvor mye skal det betales? "); var paymentAmountString = Console.ReadLine(); var paymentAmount = Convert.ToInt32(paymentAmountString); paymentHandler.AcceptPayment(paymentAmount); paymentHandler.ShowReturnAmount(); }
public CashValueList GetSetCashValueList() { CashValueList cashItemValues = new CashValueList(); cashItemValues.Add(new CashValue(1, true)); cashItemValues.Add(new CashValue(5, true)); cashItemValues.Add(new CashValue(10, true)); cashItemValues.Add(new CashValue(20, true)); cashItemValues.Add(new CashValue(50, false)); cashItemValues.Add(new CashValue(100, false)); cashItemValues.Add(new CashValue(200, false)); cashItemValues.Add(new CashValue(500, false)); cashItemValues.Add(new CashValue(1000, false)); return(cashItemValues); }
public PaymentHandler(CashValueList CVL) { List = new CashValueWithCountList(); CashItemValuesList = CVL; paymentAmount = 0; }
public PaymentHandler(CashValueList MoneyValueList) { List = new CashValueWithCountList(); CashItemValuesList = MoneyValueList; paymentAmount = 0; }