From 1178733dadbd600a66adf77bab13156fc5d9b753 Mon Sep 17 00:00:00 2001 From: "adam.hess" Date: Tue, 26 Jul 2022 12:45:48 -0400 Subject: [PATCH 1/3] init --- csharp/BetterWithAgeUpdateableItem.cs | 23 +++++++++++++++ csharp/CannedUpdatedableItem.cs | 17 +++++++++++ csharp/DoubleDegradeItem.cs | 25 ++++++++++++++++ csharp/FoodFactory.cs | 41 +++++++++++++++++++++++++++ csharp/Foods.cs | 17 +++++++++++ csharp/GenericUpdatableItem.cs | 21 ++++++++++++++ csharp/IUpdateable.cs | 15 ++++++++++ csharp/Program.cs | 2 ++ 8 files changed, 161 insertions(+) create mode 100644 csharp/BetterWithAgeUpdateableItem.cs create mode 100644 csharp/CannedUpdatedableItem.cs create mode 100644 csharp/DoubleDegradeItem.cs create mode 100644 csharp/FoodFactory.cs create mode 100644 csharp/Foods.cs create mode 100644 csharp/GenericUpdatableItem.cs create mode 100644 csharp/IUpdateable.cs diff --git a/csharp/BetterWithAgeUpdateableItem.cs b/csharp/BetterWithAgeUpdateableItem.cs new file mode 100644 index 0000000..cba8b66 --- /dev/null +++ b/csharp/BetterWithAgeUpdateableItem.cs @@ -0,0 +1,23 @@ +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++; + } + } +} 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..55e2397 --- /dev/null +++ b/csharp/DoubleDegradeItem.cs @@ -0,0 +1,25 @@ +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 (SellIn < 0) + { + Quality -= 4; + } + else + { + Quality -= 2; + } + } + } +} diff --git a/csharp/FoodFactory.cs b/csharp/FoodFactory.cs new file mode 100644 index 0000000..606141e --- /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 BetterWithAgeUpdateableItem(); + } + + 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/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..c9cbf22 100644 --- a/csharp/Program.cs +++ b/csharp/Program.cs @@ -35,6 +35,8 @@ public static void Main(string[] args) Console.WriteLine(""); app.UpdateQuality(); } + + Console.ReadKey(); } } } From 7c935f8cb86d33be2b101da121f3ff9af567a1e1 Mon Sep 17 00:00:00 2001 From: "adam.hess" Date: Tue, 26 Jul 2022 12:57:55 -0400 Subject: [PATCH 2/3] current Working Version --- csharp/DoubleDegradeItem.cs | 15 ++++++----- csharp/FoodFactory.cs | 2 +- csharp/GildedRose.cs | 50 +++---------------------------------- csharp/Program.cs | 23 +++++++++-------- csharp/csharp.csproj | 7 ++++++ 5 files changed, 34 insertions(+), 63 deletions(-) diff --git a/csharp/DoubleDegradeItem.cs b/csharp/DoubleDegradeItem.cs index 55e2397..a725b40 100644 --- a/csharp/DoubleDegradeItem.cs +++ b/csharp/DoubleDegradeItem.cs @@ -12,13 +12,16 @@ public override void UpdateQualityItem() { this.SellIn--; - if (SellIn < 0) + if (Quality > 0) { - Quality -= 4; - } - else - { - Quality -= 2; + if (SellIn < 0) + { + Quality -= 4; + } + else + { + Quality -= 2; + } } } } diff --git a/csharp/FoodFactory.cs b/csharp/FoodFactory.cs index 606141e..d029c2c 100644 --- a/csharp/FoodFactory.cs +++ b/csharp/FoodFactory.cs @@ -28,7 +28,7 @@ public static UpdateableItem Create(Foods foodType, string itemName, int sellin, } else { - item = new BetterWithAgeUpdateableItem(); + item = new GenericUpdatableItem(); } item.Name = itemName; 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/Program.cs b/csharp/Program.cs index c9cbf22..350f361 100644 --- a/csharp/Program.cs +++ b/csharp/Program.cs @@ -9,16 +9,19 @@ 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); 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 @@ + + + + + + + From d7dfec9283bf34a413783dc2f7b25847f477718b Mon Sep 17 00:00:00 2001 From: "adam.hess" Date: Tue, 26 Jul 2022 13:09:18 -0400 Subject: [PATCH 3/3] Final Code --- csharp/BetterWithAgeUpdateableItem.cs | 4 ++++ csharp/DoubleDegradeItem.cs | 5 +++++ csharp/Program.cs | 1 - 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/csharp/BetterWithAgeUpdateableItem.cs b/csharp/BetterWithAgeUpdateableItem.cs index cba8b66..5affdd2 100644 --- a/csharp/BetterWithAgeUpdateableItem.cs +++ b/csharp/BetterWithAgeUpdateableItem.cs @@ -18,6 +18,10 @@ public override void UpdateQualityItem() this.Quality++; } this.Quality++; + if (Quality > 0) + { + Quality = 50; + } } } } diff --git a/csharp/DoubleDegradeItem.cs b/csharp/DoubleDegradeItem.cs index a725b40..872611b 100644 --- a/csharp/DoubleDegradeItem.cs +++ b/csharp/DoubleDegradeItem.cs @@ -22,6 +22,11 @@ public override void UpdateQualityItem() { Quality -= 2; } + + if (Quality < 0) + { + Quality = 0; + } } } } diff --git a/csharp/Program.cs b/csharp/Program.cs index 350f361..f92b48e 100644 --- a/csharp/Program.cs +++ b/csharp/Program.cs @@ -20,7 +20,6 @@ public static void Main(string[] args) 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) };