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); }
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)); }
public float CalculateTotal(MyBasket myBasket) { float prix = 0; foreach (Article item in myBasket.articles) { prix += item.Price - (item.Price * 0.20f); } return(prix); }
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); }