Ejemplo n.º 1
0
        public void Run()
        {
            string[] input = Console.ReadLine()?
                             .Split(' ', StringSplitOptions.RemoveEmptyEntries);

            decimal pricePerDay  = decimal.Parse(input[0]);
            int     numberOfDays = int.Parse(input[1]);
            string  season       = input[2].ToLower();
            string  discountType = "none";

            if (input.Length > 3)
            {
                discountType = input[3].ToLower();
            }

            decimal totalPrice = PriceCalculator.CalculatePrice(pricePerDay,
                                                                numberOfDays,
                                                                Enum.Parse <Season>(season),
                                                                Enum.Parse <Discount>(discountType));

            Console.WriteLine($"{totalPrice:F2}");
        }
        private static PriceCalculator ReadPriceCalculator()
        {
            // <pricePerDay> <numberOfDays> <season> <discountType>
            var inputTokens = Console.ReadLine()
                              .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            var          pricePerDay  = decimal.Parse(inputTokens[0]);
            var          numberOfDays = int.Parse(inputTokens[1]);
            var          season       = (Season)Enum.Parse(typeof(Season), inputTokens[2]);
            DiscountType discountType;

            if (inputTokens.Length > 3)
            {
                discountType = (DiscountType)Enum.Parse(typeof(DiscountType), inputTokens[3]);
            }
            else
            {
                discountType = DiscountType.None;
            }

            var priceCalculator = new PriceCalculator(pricePerDay, numberOfDays, season, discountType);

            return(priceCalculator);
        }
Ejemplo n.º 3
0
        public static void Main()
        {
            var priceCalc = PriceCalculator.Parse(Console.ReadLine());

            Console.WriteLine(priceCalc.Calculate());
        }