diff --git a/Java/README.md b/Java/README.md index d64e55d1..f36fa8e5 100644 --- a/Java/README.md +++ b/Java/README.md @@ -40,4 +40,3 @@ -[x] encapsulate methods -[ ] isolate specific logics -[x] move specific logic to backstage --[x] replace items by specific objects in tests diff --git a/Java/src/main/java/com/gildedrose/GildedRose.java b/Java/src/main/java/com/gildedrose/GildedRose.java index 7bdba68d..19d6d324 100644 --- a/Java/src/main/java/com/gildedrose/GildedRose.java +++ b/Java/src/main/java/com/gildedrose/GildedRose.java @@ -8,7 +8,6 @@ import com.gildedrose.item.Sulfuras; class GildedRose { Item[] items; - public GildedRose(Item[] items) { this.items = items; } @@ -18,48 +17,59 @@ class GildedRose { final Item item = items[i]; - if (!item.name.equals(Brie.BRIE) && !item.name.equals(Backstage.BACKSTAGE)) { - if (item.quality > 0 && !item.name.equals(Sulfuras.SULFURAS)) { - decreaseQualityByOne(item); - } - } - else { - if (item.quality < 50) { - increaseQuality(item); - } - } + item.updateSellIn(); - updateSellIn(item); - - if (item.sellIn < 0) { - if (item.name.equals(Brie.BRIE)) { + if(item.name.equals(Brie.BRIE)){ + updateBrieQuality(item); + }else if (item.name.equals(Backstage.BACKSTAGE)){ + updateBackstageQuality(item); + } + else{ + if (!item.name.equals(Backstage.BACKSTAGE)) { + if (item.quality > 0 && !item.name.equals(Sulfuras.SULFURAS)) { + item.decreaseQuality(); + } + } + else { if (item.quality < 50) { item.increaseQuality(); } - } else { + } + + if (item.sellIn < 0) { if (!item.name.equals(Backstage.BACKSTAGE)) { if (!item.name.equals(Sulfuras.SULFURAS) && item.quality > 0) { - decreaseQualityByOne(item); + item.decreaseQuality(); } } else { item.quality = 0; } } } + + } } - private void decreaseQualityByOne(Item item) { - item.decreaseQuality(); - } - - private void increaseQuality(Item item) { - item.increaseQuality(); - } - - private void updateSellIn(Item item) { - if (!item.name.equals(Sulfuras.SULFURAS)) { - item.sellIn = item.sellIn - 1; + private void updateBackstageQuality(Item item) { + if (item.quality < 50) { + item.increaseQuality(); + } + if (item.sellIn < 0) { + item.quality = 0; } } + + private void updateBrieQuality(Item item) { + if (item.quality < 50) { + item.increaseQuality(); + } + if (item.sellIn < 0) { + if (item.quality < 50) { + item.increaseQuality(); + } + } + } + + } \ No newline at end of file diff --git a/Java/src/main/java/com/gildedrose/item/Brie.java b/Java/src/main/java/com/gildedrose/item/Brie.java index df6c7fe8..9fe8758f 100644 --- a/Java/src/main/java/com/gildedrose/item/Brie.java +++ b/Java/src/main/java/com/gildedrose/item/Brie.java @@ -7,4 +7,11 @@ public class Brie extends Item { public Brie(int sellIn, int quality) { super(BRIE, sellIn, quality); } + + @Override + public void increaseQuality(){ + if (this.quality < 50) { + super.increaseQuality(); + } + } } diff --git a/Java/src/main/java/com/gildedrose/item/Item.java b/Java/src/main/java/com/gildedrose/item/Item.java index 4a9d2bd2..c8611201 100644 --- a/Java/src/main/java/com/gildedrose/item/Item.java +++ b/Java/src/main/java/com/gildedrose/item/Item.java @@ -26,4 +26,8 @@ public class Item { public void increaseQuality() { this.quality = this.quality + 1; } + + public void updateSellIn() { + this.sellIn = this.sellIn - 1; + } } diff --git a/Java/src/main/java/com/gildedrose/item/Sulfuras.java b/Java/src/main/java/com/gildedrose/item/Sulfuras.java index b065dcc4..41a4bb47 100644 --- a/Java/src/main/java/com/gildedrose/item/Sulfuras.java +++ b/Java/src/main/java/com/gildedrose/item/Sulfuras.java @@ -7,4 +7,9 @@ public class Sulfuras extends Item { public Sulfuras(int sellIn, int quality) { super(SULFURAS, sellIn, quality); } + + @Override + public void updateSellIn() { + //NO-OP + } }