Exemple #1
0
        static void Main()
        {
            Console.WriteLine("Select type of card - bronze, silver or gold");
            string typeOfCard = Console.ReadLine().ToLower();

            while (typeOfCard != "bronze" && typeOfCard != "silver" && typeOfCard != "gold")
            {
                Console.WriteLine("Wrong type of card! Please select bronze, silver or gold!");
                typeOfCard = Console.ReadLine().ToLower();
            }
            Console.WriteLine("Select turnover:");
            double turnover = double.Parse(Console.ReadLine());

            while (turnover < 0)
            {
                Console.WriteLine("Invalid value! Turnover cannot be negative number!");
                turnover = double.Parse(Console.ReadLine());
            }

            Console.WriteLine("Select purchase value:");
            double purchaseValue = double.Parse(Console.ReadLine());

            while (purchaseValue < 0)
            {
                Console.WriteLine("Invalid value! Turnover cannot be negative number!");
                purchaseValue = double.Parse(Console.ReadLine());
            }

            DiscountCard discountCard;

            double discountRate = 0;
            double discount     = 0;
            double total        = 0;

            switch (typeOfCard)
            {
            case "bronze":
                discountCard = new BronzeCard(turnover, purchaseValue);
                break;

            case "silver":
                discountCard = new SilverCard(turnover, purchaseValue);
                break;

            case "gold":
                discountCard = new GoldCard(turnover, purchaseValue);
                break;

            default: throw new Exception();
            }

            discountRate = discountCard.CalculateDiscountRate();
            discount     = discountCard.CalculateDiscount();
            total        = discountCard.TotalValue();

            Console.WriteLine($"Purchase value: ${purchaseValue:f2}");
            Console.WriteLine($"Discount rate: {discountRate:f1}%");
            Console.WriteLine($"Discount: ${discount:f2}");
            Console.WriteLine($"Total: ${total:f2}");
        }
Exemple #2
0
        static void Main(string[] args)
        {
            BronzeCard bronzeCard          = new BronzeCard(150);
            double     bronzePurchaseValue = 150;

            Console.WriteLine("Bronze card: ");
            Console.WriteLine("Purchase value: ${0}", bronzePurchaseValue);
            Console.WriteLine("Discount rate: {0}%", bronzeCard.getRate());
            Console.WriteLine("Discount: ${0}", bronzeCard.calculateDiscount(bronzePurchaseValue));
            Console.WriteLine("Total: ${0}", bronzeCard.CalculateTotal(bronzePurchaseValue));

            Console.WriteLine();

            SilverCard silverCard          = new SilverCard(600);
            double     silverPurchaseValue = 850;

            Console.WriteLine("Silver card: ");
            Console.WriteLine("Purchase value: ${0}", silverPurchaseValue);
            Console.WriteLine("Discount rate: {0}%", silverCard.calculateRate());
            Console.WriteLine("Discount: ${0}", silverCard.calculateDiscount(silverPurchaseValue));
            Console.WriteLine("Total: ${0}", silverCard.CalculateTotal(silverPurchaseValue));

            Console.WriteLine();

            GoldCard goldCard          = new GoldCard(1500);
            double   goldPurchaseValue = 1300;

            Console.WriteLine("Gold card: ");
            Console.WriteLine("Purchase value: ${0}", goldPurchaseValue);
            Console.WriteLine("Discount rate: {0}%", goldCard.calculateRate());
            Console.WriteLine("Discount: ${0}", goldCard.calculateDiscount(goldPurchaseValue));
            Console.WriteLine("Total: ${0}", goldCard.CalculateTotal(goldPurchaseValue));
        }
Exemple #3
0
        static void Main(string[] args)
        {
            var bronzeCard = new BronzeCard(150, 0);

            Console.WriteLine(bronzeCard.GetDiscount());

            var silverCard = new SilverCard(850, 600);

            Console.WriteLine(silverCard.GetDiscount());

            var goldCard = new GoldCard(1300, 1500);

            Console.WriteLine(goldCard.GetDiscount());
        }
Exemple #4
0
        static void Main(string[] args)
        {
            IWriter  writer         = new ConsoleWriter();
            ICard    BronzeCard     = new BronzeCard();
            ICard    SilverCard     = new SilverCard();
            ICard    GoldCard       = new GoldCard();
            Purchase FirstPurchase  = BronzeCard.CalculatePurchase(0, 150);
            Purchase SecondPurchase = SilverCard.CalculatePurchase(600, 850);
            Purchase ThirdPurchase  = GoldCard.CalculatePurchase(1500, 1300);

            writer.PrintPurchase(FirstPurchase);
            Console.WriteLine();
            writer.PrintPurchase(SecondPurchase);
            Console.WriteLine();
            writer.PrintPurchase(ThirdPurchase);
        }
Exemple #5
0
        public static void Main()
        {
            ICard bronzeCard = new BronzeCard(0);
            ICard silverCard = new SilverCard(600);
            ICard goldCard   = new GoldCard(1500);

            string bronzeCardResult = PayDesk.CalulateDiscount(150, bronzeCard);
            string silverCardResult = PayDesk.CalulateDiscount(850, silverCard);
            string goldCardResult   = PayDesk.CalulateDiscount(1300, goldCard);

            Console.WriteLine(bronzeCardResult);
            Console.WriteLine();
            Console.WriteLine(silverCardResult);
            Console.WriteLine();
            Console.WriteLine(goldCardResult);
        }
Exemple #6
0
        static void Main(string[] args)
        {
            try
            {
                BronzeCard Bronze_Card = new BronzeCard("Nikola", 0);
                Bronze_Card.Discount_calculations(150);


                SilverCard Silver_Card = new SilverCard("Viktor", 600);
                Silver_Card.Discount_calculations(850);

                GoldCard Gold_Card = new GoldCard("Dimitar", 1500);
                Gold_Card.Discount_calculations(1300);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception {0} thrown.", e.GetType().FullName);
                Console.WriteLine("Message:\n\"{0}\"", e.Message);
            }



            Console.ReadKey();
        }//Main