예제 #1
0
        static void Main(string[] args)
        {
            var cardFactory = new CardFactory();

            string input = Console.ReadLine();

            try
            {
                string[] inputParams = input.Split(new [] { ", " }, StringSplitOptions.RemoveEmptyEntries);

                if (inputParams.Length != 3)
                {
                    throw new Exception("The input must consist of card type, turnover and purchase value!");
                }
                string  typeCard      = inputParams[0];
                decimal turnover      = decimal.Parse(inputParams[1]);
                decimal purchaseValue = decimal.Parse(inputParams[2]);

                Card card         = cardFactory.CreateCard(typeCard, turnover);
                var  discountRate = card.DiscountRate;

                Console.WriteLine(PayDesk.GetOutput(purchaseValue, discountRate));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
예제 #2
0
        public static void Main()
        {
            var owner         = string.Empty;
            var cardType      = string.Empty;
            var turnover      = 0.0m;
            var purchaseValue = 0.0;

            try
            {
                Console.WriteLine("Please enter client name.");
                owner = Console.ReadLine();

                Console.WriteLine("Please enter one of this three different types of discount cards: gold, silver or bronze!");
                var inputCardType = Console.ReadLine().ToUpper();
                cardType = GetCardType(inputCardType);

                Console.WriteLine("Please enter turnower.");
                turnover = decimal.Parse(Console.ReadLine());
                if (turnover < 0)
                {
                    throw new ArgumentException();
                }

                Console.WriteLine("Please enter purchase value.");
                purchaseValue = double.Parse(Console.ReadLine());
                if (purchaseValue < 0)
                {
                    throw new ArgumentException();
                }
            }
            catch (AggregateException)
            {
                Console.WriteLine("Please enter valid information");
                throw;
            }
            var card        = PayDesk.CreateCart(owner, cardType);
            var textToPrind = PayDesk.calculateResultToPrint(turnover, purchaseValue, card);

            Console.WriteLine(textToPrind);
        }