Beispiel #1
0
        // utility
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            FinalizedCoffees?.ToList().ForEach(c => sb.AppendLine(c.ToString()));
            sb.AppendLine();
            sb.AppendLine($"The total cost of your order is ${GetTotalPrice()}");
            return(sb.ToString());
        }
Beispiel #2
0
        // Transaction-based methods
        public string CompleteTransaction()
        {
            // This validation calls for some refactoring
            decimal change = MoneyAdded - GetTotalPrice();

            if (!FinalizedCoffees.ToList().Any())
            {
                throw new TransactionCompletedWithoutOrdersException("A transaction cannot be completed because there are currently no coffees ordered.");
            }
            if (change < 0)
            {
                throw new InvalidMoneyException($"You have not provided sufficient money to cover the cost of the order.  Please add {change}.");
            }

            // Not sure why but couldn't get FinalizedCoffees.ToList().Clear() to work
            // Do want to get rid of this initialization here
            FinalizedCoffees = new List <ICoffee>();

            return($"Thank you for your patronage.  Your change is: {change}");
        }