diff --git a/csharp/BetterWithAgeUpdateableItem.cs b/csharp/BetterWithAgeUpdateableItem.cs new file mode 100644 index 0000000..5affdd2 --- /dev/null +++ b/csharp/BetterWithAgeUpdateableItem.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace csharp +{ + internal class BetterWithAgeUpdateableItem : UpdateableItem + { + public override void UpdateQualityItem() + { + + SellIn--; + if (this.Quality >= 50) return; + if (this.SellIn < 0) + { + this.Quality++; + } + this.Quality++; + if (Quality > 0) + { + Quality = 50; + } + } + } +} diff --git a/csharp/CannedUpdatedableItem.cs b/csharp/CannedUpdatedableItem.cs new file mode 100644 index 0000000..258a59a --- /dev/null +++ b/csharp/CannedUpdatedableItem.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace csharp +{ + internal class CannedUpdatedableItem : UpdateableItem + { + public override void UpdateQualityItem() + { + this.Quality = 80; + return; + } + } +} diff --git a/csharp/DoubleDegradeItem.cs b/csharp/DoubleDegradeItem.cs new file mode 100644 index 0000000..872611b --- /dev/null +++ b/csharp/DoubleDegradeItem.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace csharp +{ + internal class DoubleDegradeItem : UpdateableItem + { + public override void UpdateQualityItem() + { + this.SellIn--; + + if (Quality > 0) + { + if (SellIn < 0) + { + Quality -= 4; + } + else + { + Quality -= 2; + } + + if (Quality < 0) + { + Quality = 0; + } + } + } + } +} diff --git a/csharp/FoodFactory.cs b/csharp/FoodFactory.cs new file mode 100644 index 0000000..d029c2c --- /dev/null +++ b/csharp/FoodFactory.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Remoting.Messaging; +using System.Text; +using System.Threading.Tasks; + +namespace csharp +{ + internal class FoodItemFactory + { + + public static UpdateableItem Create(Foods foodType, string itemName, int sellin, int quality) + { + UpdateableItem item; + if (foodType == Foods.AgedBrie) + { + item = new BetterWithAgeUpdateableItem(); + } + else if (foodType == Foods.CannedBeans) + { + item = new CannedUpdatedableItem(); + + } + else if (foodType == Foods.DoubleDegradeItem) + { + item = new DoubleDegradeItem(); + } + else + { + item = new GenericUpdatableItem(); + } + + item.Name = itemName; + item.Quality = quality; + item.SellIn = sellin; + return item; + + } + } +} diff --git a/csharp/Foods.cs b/csharp/Foods.cs new file mode 100644 index 0000000..3b08a4f --- /dev/null +++ b/csharp/Foods.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace csharp +{ + internal enum Foods + { + CannedBeans, + AgedBrie, + GenericItem, + DoubleDegradeItem + + } +} diff --git a/csharp/GenericUpdatableItem.cs b/csharp/GenericUpdatableItem.cs new file mode 100644 index 0000000..dfc58b1 --- /dev/null +++ b/csharp/GenericUpdatableItem.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace csharp +{ + internal class GenericUpdatableItem : UpdateableItem + { + public override void UpdateQualityItem() + { + + SellIn--; + if (SellIn < 0 && this.Quality > 0) + { + this.Quality--; + } + } + } +} diff --git a/csharp/GildedRose.cs b/csharp/GildedRose.cs index 3092424..1793071 100644 --- a/csharp/GildedRose.cs +++ b/csharp/GildedRose.cs @@ -4,59 +4,17 @@ namespace csharp { public class GildedRose { - IList Items; - public GildedRose(IList Items) + IList Items; + public GildedRose(IList Items) { this.Items = Items; } public void UpdateQuality() { - for (var i = 0; i < Items.Count; i++) + foreach (UpdateableItem item in Items) { - if (Items[i].Name != "Canned Beans") - { - Items[i].SellIn = Items[i].SellIn - 1; - } - - if (Items[i].Name == "Aged Brie") - { - if (Items[i].Quality < 50) - { - Items[i].Quality = Items[i].Quality + 1; - } - } - else - { - if (Items[i].Quality > 0) - { - if (Items[i].Name != "Canned Beans") - { - Items[i].Quality = Items[i].Quality - 1; - } - } - } - - if (Items[i].SellIn < 0) - { - if (Items[i].Name == "Aged Brie") - { - if (Items[i].Quality < 50) - { - Items[i].Quality = Items[i].Quality + 1; - } - } - else - { - if (Items[i].Quality > 0) - { - if (Items[i].Name != "Canned Beans") - { - Items[i].Quality = Items[i].Quality - 1; - } - } - } - } + item.UpdateQualityItem(); } } } diff --git a/csharp/IUpdateable.cs b/csharp/IUpdateable.cs new file mode 100644 index 0000000..b137dc4 --- /dev/null +++ b/csharp/IUpdateable.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace csharp +{ + public abstract class UpdateableItem : Item + { + + public abstract void UpdateQualityItem(); + + } +} diff --git a/csharp/Program.cs b/csharp/Program.cs index f80ecee..f92b48e 100644 --- a/csharp/Program.cs +++ b/csharp/Program.cs @@ -9,16 +9,18 @@ public class Program public static void Main(string[] args) { - IList Items = new List{ - new Item {Name = "Bananas", SellIn = 10, Quality = 20}, - new Item {Name = "Aged Brie", SellIn = 2, Quality = 0}, - new Item {Name = "Eggs", SellIn = 5, Quality = 7}, - new Item {Name = "Eggs", SellIn = 12, Quality = 5}, - new Item {Name = "Canned Beans", SellIn = 0, Quality = 80}, - new Item {Name = "Canned Beans", SellIn = -1, Quality = 80}, - - // This Baked good does not work properly yet! - new Item {Name = "Baked Sourdough Bread", SellIn = 3, Quality = 6} + var Items = new List + { + + FoodItemFactory.Create(Foods.GenericItem, "Bananas", 10, 20), + FoodItemFactory.Create(Foods.AgedBrie, "Aged Brie", 2, 0), + + FoodItemFactory.Create(Foods.GenericItem, "Eggs", 5, 7), + FoodItemFactory.Create(Foods.GenericItem, "Eggs", 12, 5), + + FoodItemFactory.Create(Foods.CannedBeans, "Canned Beans", 0, 80), + FoodItemFactory.Create(Foods.CannedBeans, "Canned Beans", -1, 80), + FoodItemFactory.Create(Foods.DoubleDegradeItem, "Baked Sourdough Bread", 3, 6) }; var app = new GildedRose(Items); @@ -35,6 +37,8 @@ public static void Main(string[] args) Console.WriteLine(""); app.UpdateQuality(); } + + Console.ReadKey(); } } } diff --git a/csharp/csharp.csproj b/csharp/csharp.csproj index 1c34779..d1f954c 100644 --- a/csharp/csharp.csproj +++ b/csharp/csharp.csproj @@ -45,8 +45,15 @@ + + + + + + +