Example #1
0
        public float CalculateTotal(MyBasket myBasket)
        {
            float prix = 0;

            foreach (Article item in myBasket.articles)
            {
                prix += item.Price;
            }
            return(myBasket.articles.Length >= 5 ? prix * 0.70f : myBasket.articles.Length >= 4 ? prix * 0.75f : myBasket.articles.Length >= 3 ? prix * 0.80f : myBasket.articles.Length >= 2 ? prix * 0.90f : prix);
        }
Example #2
0
 public float CalculateTotal(MyBasket myBasket)
 {
     /*float prix = 0;
      * foreach (Article item in myBasket.articles)
      * {
      *  prix += item.Price;
      * }
      * return prix;*/
     return(myBasket.articles.Sum(a => a.Price));
 }
Example #3
0
        public float CalculateTotal(MyBasket myBasket)
        {
            float prix = 0;

            foreach (Article item in myBasket.articles)
            {
                prix += item.Price - (item.Price * 0.20f);
            }
            return(prix);
        }
Example #4
0
        static void Main(string[] args)
        {
            MyBasket chochi = new MyBasket();

            chochi.FillBasket(new Article("Pizza", 2.5f), new Article("Milk", 4.5f), new Article("Teddy Bear", 5.5f), new Article("Shampoo", 9.8f));

            Console.Write(chochi);

            chochi.ChoosePaymentStrategy(new NormalPayement());
            Console.WriteLine($"The total price with a normal payement is {chochi.TotalPrice}");

            chochi.ChoosePaymentStrategy(new GiftedVAT());
            Console.WriteLine($"The total price with a gifted VAT payement is {chochi.TotalPrice}$");
            chochi.ChoosePaymentStrategy(new StagesPayement());
            Console.WriteLine($"The total price with a stages payement is  {chochi.TotalPrice}");
            Console.ReadKey(true);
        }