From c7ecd14b9c30b35524005f286e8b13f956f4a2ab Mon Sep 17 00:00:00 2001 From: chaen-ing Date: Mon, 30 Sep 2024 13:48:11 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/gildedrose/GildedRose.java | 96 +++++++++++++------ .../com/gildedrose/update/UpdateItem.java | 22 +++++ .../update/UpdateItemBackStage.java | 19 ++++ .../com/gildedrose/update/UpdateItemBrie.java | 15 +++ .../gildedrose/update/UpdateItemConjured.java | 13 +++ .../gildedrose/update/UpdateItemStandard.java | 12 +++ .../gildedrose/update/UpdateItemSulfuras.java | 10 ++ 7 files changed, 156 insertions(+), 31 deletions(-) create mode 100644 Java/src/main/java/com/gildedrose/update/UpdateItem.java create mode 100644 Java/src/main/java/com/gildedrose/update/UpdateItemBackStage.java create mode 100644 Java/src/main/java/com/gildedrose/update/UpdateItemBrie.java create mode 100644 Java/src/main/java/com/gildedrose/update/UpdateItemConjured.java create mode 100644 Java/src/main/java/com/gildedrose/update/UpdateItemStandard.java create mode 100644 Java/src/main/java/com/gildedrose/update/UpdateItemSulfuras.java diff --git a/Java/src/main/java/com/gildedrose/GildedRose.java b/Java/src/main/java/com/gildedrose/GildedRose.java index 87a3b92..059bb06 100644 --- a/Java/src/main/java/com/gildedrose/GildedRose.java +++ b/Java/src/main/java/com/gildedrose/GildedRose.java @@ -1,5 +1,14 @@ package com.gildedrose; +import java.util.HashMap; + +import com.gildedrose.update.UpdateItem; +import com.gildedrose.update.UpdateItemBackStage; +import com.gildedrose.update.UpdateItemBrie; +import com.gildedrose.update.UpdateItemConjured; +import com.gildedrose.update.UpdateItemStandard; +import com.gildedrose.update.UpdateItemSulfuras; + class GildedRose { Item[] items; @@ -7,56 +16,81 @@ public GildedRose(Item[] items) { this.items = items; } + public void updateQuality() { - for (int i = 0; i < items.length; i++) { - if (!items[i].name.equals("Aged Brie") - && !items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { - if (items[i].quality > 0) { - if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { - items[i].quality = items[i].quality - 1; - } + HashMap updaters = new HashMap<>(); + updaters.put("Aged Brie", new UpdateItemBrie()); + updaters.put("Backstage passes to a TAFKAL80ETC concert", new UpdateItemBackStage()); + updaters.put("Sulfuras, Hand of Ragnaros", new UpdateItemSulfuras()); + updaters.put("Conjured Mana Cake", new UpdateItemConjured()); + + UpdateItemStandard updateItemStandard = new UpdateItemStandard(); + + for (Item item : items) { + updaters.getOrDefault(item.name,updateItemStandard).update(item); + } + } + +} + + +/* + public void updateQuality() { + + for (Item item : items) { + if (!item.name.equals("Aged Brie") // 브리치즈, 콘서트 티켓이 아닌 경우 -> 일반 아이템 + && !item.name.equals("Backstage passes to a TAFKAL80ETC concert")) { + if (item.quality > 0) { + if (!item.name.equals("Sulfuras, Hand of Ragnaros")) { + item.quality = item.quality - 1; + } // Sulfuras 아닌 경우 1 감소 } - } else { - if (items[i].quality < 50) { - items[i].quality = items[i].quality + 1; - - if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { - if (items[i].sellIn < 11) { - if (items[i].quality < 50) { - items[i].quality = items[i].quality + 1; + } else { // 브리치즈 or 콘서트 티켓인 경우 + if (item.quality < 50) { + item.quality = item.quality + 1; // 가치 50 미만이면 1 증가 + + // 콘서트 티켓 + if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) { + if (item.sellIn < 11) { // 10일 이하면 가치 총 2 증가 + if (item.quality < 50) { + item.quality = item.quality + 1; } } - if (items[i].sellIn < 6) { - if (items[i].quality < 50) { - items[i].quality = items[i].quality + 1; + if (item.sellIn < 6) { // 5일 이하면 가치 총 3 증가 + if (item.quality < 50) { + item.quality = item.quality + 1; } } } } } - if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { - items[i].sellIn = items[i].sellIn - 1; + if (!item.name.equals("Sulfuras, Hand of Ragnaros")) { + item.sellIn = item.sellIn - 1; // Surfuras는 기간 감소 x } - if (items[i].sellIn < 0) { - if (!items[i].name.equals("Aged Brie")) { - if (!items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { - if (items[i].quality > 0) { - if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { - items[i].quality = items[i].quality - 1; + if (item.sellIn < 0) { // 남은 기간이 0 미만 + if (!item.name.equals("Aged Brie")) { + if (!item.name.equals("Backstage passes to a TAFKAL80ETC concert")) { + if (item.quality > 0) { + if (!item.name.equals("Sulfuras, Hand of Ragnaros")) { + item.quality = item.quality - 1; // 브리, 콘서트, Sulfuras 다 아님 -> 일반 아이템 : 총 2씩 감소 } } } else { - items[i].quality = items[i].quality - items[i].quality; + item.quality = item.quality - item.quality; // 콘서트 가치 0 } - } else { - if (items[i].quality < 50) { - items[i].quality = items[i].quality + 1; + } else { // 브리치즈는 총 2씩 증가 + if (item.quality < 50) { + item.quality = item.quality + 1; } } } } + } -} + + } + +*/ diff --git a/Java/src/main/java/com/gildedrose/update/UpdateItem.java b/Java/src/main/java/com/gildedrose/update/UpdateItem.java new file mode 100644 index 0000000..8a1fcf8 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/update/UpdateItem.java @@ -0,0 +1,22 @@ +package com.gildedrose.update; + +import com.gildedrose.Item; + +public interface UpdateItem { + static final int MAX_QUALITY = 50; + static final int MIN_QUALITY = 0; + + public void update(Item item); + + static void decreaseSellIn(Item item) {item.sellIn -= 1;} + + static void increaseQuality(Item item) { + if(item.quality < MAX_QUALITY) item.quality += 1; + } + + static void decreaseQuality(Item item) { + if(item.quality > MIN_QUALITY) item.quality -= 1; + } + + +} diff --git a/Java/src/main/java/com/gildedrose/update/UpdateItemBackStage.java b/Java/src/main/java/com/gildedrose/update/UpdateItemBackStage.java new file mode 100644 index 0000000..48c0205 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/update/UpdateItemBackStage.java @@ -0,0 +1,19 @@ +package com.gildedrose.update; + +import com.gildedrose.Item; + +public class UpdateItemBackStage implements UpdateItem{ + @Override + public void update(Item item) { + UpdateItem.decreaseSellIn(item); + + if (item.sellIn < 0) { + item.quality = 0; + return; + } + + UpdateItem.increaseQuality(item); + if(item.sellIn < 11) UpdateItem.increaseQuality(item); + if(item.sellIn < 6) UpdateItem.increaseQuality(item); + } +} diff --git a/Java/src/main/java/com/gildedrose/update/UpdateItemBrie.java b/Java/src/main/java/com/gildedrose/update/UpdateItemBrie.java new file mode 100644 index 0000000..f0ceaf7 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/update/UpdateItemBrie.java @@ -0,0 +1,15 @@ +package com.gildedrose.update; + +import com.gildedrose.Item; +import com.gildedrose.update.UpdateItem; + +public class UpdateItemBrie implements UpdateItem { + + @Override + public void update(Item item) { + UpdateItem.decreaseSellIn(item); + + UpdateItem.increaseQuality(item); + if(item.sellIn < 0) UpdateItem.increaseQuality(item); + } +} diff --git a/Java/src/main/java/com/gildedrose/update/UpdateItemConjured.java b/Java/src/main/java/com/gildedrose/update/UpdateItemConjured.java new file mode 100644 index 0000000..8f303fd --- /dev/null +++ b/Java/src/main/java/com/gildedrose/update/UpdateItemConjured.java @@ -0,0 +1,13 @@ +package com.gildedrose.update; + +import com.gildedrose.Item; + +public class UpdateItemConjured implements UpdateItem{ + @Override + public void update(Item item) { + UpdateItem.decreaseSellIn(item); + + UpdateItem.decreaseQuality(item); + UpdateItem.decreaseQuality(item); + } +} diff --git a/Java/src/main/java/com/gildedrose/update/UpdateItemStandard.java b/Java/src/main/java/com/gildedrose/update/UpdateItemStandard.java new file mode 100644 index 0000000..93d1ec9 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/update/UpdateItemStandard.java @@ -0,0 +1,12 @@ +package com.gildedrose.update; + +import com.gildedrose.Item; + +public class UpdateItemStandard implements UpdateItem{ + @Override + public void update(Item item) { + UpdateItem.decreaseSellIn(item); + + UpdateItem.decreaseQuality(item); + } +} diff --git a/Java/src/main/java/com/gildedrose/update/UpdateItemSulfuras.java b/Java/src/main/java/com/gildedrose/update/UpdateItemSulfuras.java new file mode 100644 index 0000000..a19d117 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/update/UpdateItemSulfuras.java @@ -0,0 +1,10 @@ +package com.gildedrose.update; + +import com.gildedrose.Item; + +public class UpdateItemSulfuras implements UpdateItem{ + @Override + public void update(Item item) { + + } +}