From 78a7b1a6c1a362ed2ebd52fef24593b686e1c905 Mon Sep 17 00:00:00 2001 From: Ludovic Lagouardette Date: Wed, 8 Jun 2022 16:30:29 +0200 Subject: [PATCH] Yes --- Beverages/Coffee.cs | 12 +++++++++ Beverages/Erythriol.cs | 23 ++++++++++++++++ Beverages/IBeverage.cs | 4 ++- Beverages/IPhysicalProperties.cs | 3 ++- Beverages/ISweetener.cs | 2 +- Beverages/Tea.cs | 45 ++++++++++++++++++++++++++++++++ Exercice2/Program.cs | 10 +++---- 7 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 Beverages/Coffee.cs create mode 100644 Beverages/Erythriol.cs create mode 100644 Beverages/Tea.cs diff --git a/Beverages/Coffee.cs b/Beverages/Coffee.cs new file mode 100644 index 0000000..5f928ef --- /dev/null +++ b/Beverages/Coffee.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Beverages +{ + class Coffee + { + } +} diff --git a/Beverages/Erythriol.cs b/Beverages/Erythriol.cs new file mode 100644 index 0000000..9d1cbfd --- /dev/null +++ b/Beverages/Erythriol.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Beverages +{ + public class Erythriol : ISweetener + { + double quantityGrams; + + public Erythriol(double quantityGrams) + { + this.quantityGrams = quantityGrams; + } + + public override string ToString() + { + return "Erythriol " + quantityGrams + "g"; + } + } +} diff --git a/Beverages/IBeverage.cs b/Beverages/IBeverage.cs index 7b248d1..5f08b4a 100644 --- a/Beverages/IBeverage.cs +++ b/Beverages/IBeverage.cs @@ -6,7 +6,9 @@ using System.Threading.Tasks; namespace Beverages { - interface IBeverage + public interface IBeverage : IPhysicalProperties { + void Sweeten(ISweetener sweetener); + List GetSweetenersList(); } } diff --git a/Beverages/IPhysicalProperties.cs b/Beverages/IPhysicalProperties.cs index 3438756..b87bcf6 100644 --- a/Beverages/IPhysicalProperties.cs +++ b/Beverages/IPhysicalProperties.cs @@ -6,7 +6,8 @@ using System.Threading.Tasks; namespace Beverages { - interface IPhysicalProperties + public interface IPhysicalProperties { + float GetTemperature(); } } diff --git a/Beverages/ISweetener.cs b/Beverages/ISweetener.cs index 6512511..d36ad2a 100644 --- a/Beverages/ISweetener.cs +++ b/Beverages/ISweetener.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Beverages { - interface ISweetener + public interface ISweetener { } } diff --git a/Beverages/Tea.cs b/Beverages/Tea.cs new file mode 100644 index 0000000..07b9c72 --- /dev/null +++ b/Beverages/Tea.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Beverages +{ + public enum TeaType + { + Oolong, + Iced + } + + public class Tea : IBeverage + { + TeaType type; + List sweeteners; + + public Tea(TeaType type) + { + this.type = type; + sweeteners = new List(); + } + + public List GetSweetenersList() + { + return sweeteners; + } + + public void Sweeten(ISweetener sweetener) + { + sweeteners.Add(sweetener); + } + + public float GetTemperature() + { + if (type == TeaType.Iced) + { + return 5; + } + return 98; + } + } +} diff --git a/Exercice2/Program.cs b/Exercice2/Program.cs index 249d39b..ed1404e 100644 --- a/Exercice2/Program.cs +++ b/Exercice2/Program.cs @@ -13,10 +13,10 @@ namespace Exercice2 ISweetener sugar = new Erythriol(0.5); tea.Sweeten(sugar); - Debug.Assert(tea.GetSweetenersList().Count == 1, "We put a single sweetener type"); - - IBeverage coffee = new Coffee(CoffeeType.ColdBrew); - Debug.Assert(coffee.GetTemperature() < (float)5, "Coldbrew coffee temperature needs be below 5C"); + Debug.Assert(tea.GetSweetenersList().Count == 2, "We put a single sweetener type"); + + /*IBeverage coffee = new Coffee(CoffeeType.ColdBrew); + Debug.Assert(coffee.GetTemperature() <= (float)5, "Coldbrew coffee temperature needs be below 5C"); IBeverage horror = new Mix(tea, coffee); Debug.Assert(horror.GetTemperature() < (float)55, "Horror temperature needs be average of tea and coffee"); @@ -24,7 +24,7 @@ namespace Exercice2 ISweetener coffeeSugar = new Erythriol(0.5); coffee.Sweeten(coffeeSugar); - Debug.Assert(horror.GetSweetenersList().Count == 1, "We put a single sweetener type, just more of it"); + Debug.Assert(horror.GetSweetenersList().Count == 1, "We put a single sweetener type, just more of it");*/ } } }