diff --git a/Java/gradle/wrapper/gradle-wrapper.jar b/Java/gradle/wrapper/gradle-wrapper.jar index cc4fdc2..7454180 100644 Binary files a/Java/gradle/wrapper/gradle-wrapper.jar and b/Java/gradle/wrapper/gradle-wrapper.jar differ diff --git a/Java/gradle/wrapper/gradle-wrapper.properties b/Java/gradle/wrapper/gradle-wrapper.properties index 622ab64..ffed3a2 100644 --- a/Java/gradle/wrapper/gradle-wrapper.properties +++ b/Java/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/Java/src/main/java/com/gildedrose/GildedRose.java b/Java/src/main/java/com/gildedrose/GildedRose.java index 87a3b92..25f60ee 100644 --- a/Java/src/main/java/com/gildedrose/GildedRose.java +++ b/Java/src/main/java/com/gildedrose/GildedRose.java @@ -1,62 +1,21 @@ package com.gildedrose; +import com.gildedrose.update.UpdateLogic; +import com.gildedrose.update.UpdateLogicFactory; + class GildedRose { Item[] items; + UpdateLogicFactory updateLogicFactory; public GildedRose(Item[] items) { this.items = items; + updateLogicFactory = new UpdateLogicFactory(); } 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; - } - } - } 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; - } - } - - if (items[i].sellIn < 6) { - if (items[i].quality < 50) { - items[i].quality = items[i].quality + 1; - } - } - } - } - } - - if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { - items[i].sellIn = items[i].sellIn - 1; - } - - 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; - } - } - } else { - items[i].quality = items[i].quality - items[i].quality; - } - } else { - if (items[i].quality < 50) { - items[i].quality = items[i].quality + 1; - } - } - } + for (Item item : items) { + UpdateLogic updateLogic = updateLogicFactory.getUpdateLogic(item); + updateLogic.update(item); } } } diff --git a/Java/src/main/java/com/gildedrose/update/AgedBrie.java b/Java/src/main/java/com/gildedrose/update/AgedBrie.java new file mode 100644 index 0000000..a6e50dd --- /dev/null +++ b/Java/src/main/java/com/gildedrose/update/AgedBrie.java @@ -0,0 +1,19 @@ +package com.gildedrose.update; + +import static com.gildedrose.update.ItemConstants.*; + +import com.gildedrose.Item; + +public class AgedBrie extends UpdateLogic { + + @Override + public void update(Item item) { + + increaseQuality(item, DEFAULT_QUALITY_INCREMENT); + decreaseSellIn(item); + + if (item.sellIn < QUALITY_MIN) { + increaseQuality(item, DEFAULT_QUALITY_INCREMENT); + } + } +} diff --git a/Java/src/main/java/com/gildedrose/update/BackstagePass.java b/Java/src/main/java/com/gildedrose/update/BackstagePass.java new file mode 100644 index 0000000..1beb546 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/update/BackstagePass.java @@ -0,0 +1,33 @@ +package com.gildedrose.update; + +import static com.gildedrose.update.ItemConstants.*; + +import com.gildedrose.Item; + +public class BackstagePass extends UpdateLogic { + + private static final int BACKSTAGE_SELL_IN_THRESHOLD_10 = 10; + private static final int BACKSTAGE_SELL_IN_THRESHOLD_5 = 5; + + @Override + public void update(Item item) { + + // 판매 기한이 10일 이하일 때 품질 1 증가 + if (item.sellIn <= BACKSTAGE_SELL_IN_THRESHOLD_10) { + increaseQuality(item, DEFAULT_QUALITY_INCREMENT); + } + + // 판매 기한이 5일 이하일 때 추가로 품질 1 증가 + if (item.sellIn <= BACKSTAGE_SELL_IN_THRESHOLD_5) { + increaseQuality(item, DEFAULT_QUALITY_INCREMENT); + } + + // 판매 기한 1일 감소 + decreaseSellIn(item); + + // 판매 기한이 지난 경우 품질을 0으로 설정 + if (item.sellIn < QUALITY_MIN) { + item.quality = QUALITY_MIN; + } + } +} diff --git a/Java/src/main/java/com/gildedrose/update/Conjured.java b/Java/src/main/java/com/gildedrose/update/Conjured.java new file mode 100644 index 0000000..e47cd95 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/update/Conjured.java @@ -0,0 +1,25 @@ +package com.gildedrose.update; + +import static com.gildedrose.update.ItemConstants.*; + +import com.gildedrose.Item; + +public class Conjured extends UpdateLogic { + + @Override + public void update(Item item) { + + //"Conjured" 아이템은 일반 아이템의 2배의 속도로 품질(Quality)이 저하 + decreaseQuality(item, QUALITY_DECREMENT_MULTIPLIER); + decreaseSellIn(item); + + // 판매 기한이 0일 이하인 경우, 품질(Quality)을 추가로 2배 감소 + if (item.sellIn < QUALITY_MIN && item.quality > QUALITY_MIN) { + item.quality -= QUALITY_DECREMENT_MULTIPLIER; + } + + if (item.quality < QUALITY_MIN) { + item.quality = QUALITY_MIN; + } + } +} diff --git a/Java/src/main/java/com/gildedrose/update/DefaultItem.java b/Java/src/main/java/com/gildedrose/update/DefaultItem.java new file mode 100644 index 0000000..3350e32 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/update/DefaultItem.java @@ -0,0 +1,19 @@ +package com.gildedrose.update; + +import static com.gildedrose.update.ItemConstants.*; + +import com.gildedrose.Item; + +public class DefaultItem extends UpdateLogic{ + + @Override + public void update(Item item) { + + decreaseQuality(item, DEFAULT_QUALITY_DECREMENT); + decreaseSellIn(item); + + if (item.sellIn < 0) { + decreaseQuality(item, DEFAULT_QUALITY_DECREMENT); + } + } +} diff --git a/Java/src/main/java/com/gildedrose/update/ItemConstants.java b/Java/src/main/java/com/gildedrose/update/ItemConstants.java new file mode 100644 index 0000000..2c2e8c2 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/update/ItemConstants.java @@ -0,0 +1,9 @@ +package com.gildedrose.update; + +public class ItemConstants { + public static final int QUALITY_MAX = 50; + public static final int QUALITY_MIN = 0; + public static final int DEFAULT_QUALITY_INCREMENT = 1; + public static final int DEFAULT_QUALITY_DECREMENT = 1; + public static final int QUALITY_DECREMENT_MULTIPLIER = 2; +} diff --git a/Java/src/main/java/com/gildedrose/update/Sulfuras.java b/Java/src/main/java/com/gildedrose/update/Sulfuras.java new file mode 100644 index 0000000..13d5c91 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/update/Sulfuras.java @@ -0,0 +1,10 @@ +package com.gildedrose.update; + +import com.gildedrose.Item; + +public class Sulfuras extends UpdateLogic { + @Override + public void update(Item item) { + + } +} diff --git a/Java/src/main/java/com/gildedrose/update/UpdateLogic.java b/Java/src/main/java/com/gildedrose/update/UpdateLogic.java new file mode 100644 index 0000000..1313f73 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/update/UpdateLogic.java @@ -0,0 +1,25 @@ +package com.gildedrose.update; + +import static com.gildedrose.update.ItemConstants.*; + +import com.gildedrose.Item; + +public abstract class UpdateLogic { + + //판매일(SellIn) 감소 + public void decreaseSellIn(Item item) { + item.sellIn--; + } + + //품질(Quality)를 지정한 increment만큼 증가 + public void increaseQuality(Item item, int increment) { + item.quality = Math.min(item.quality + increment, QUALITY_MAX); // QUALITY_MAX 이상으로 증가하지 않음 + } + + //품질(Quality)를 지정한 decrement만큼 감소 + public void decreaseQuality(Item item, int decrement) { + item.quality = Math.max(item.quality - decrement, QUALITY_MIN); // QUALITY_MIN 이하로 감소하지 않음 + } + + public abstract void update(Item item); +} diff --git a/Java/src/main/java/com/gildedrose/update/UpdateLogicFactory.java b/Java/src/main/java/com/gildedrose/update/UpdateLogicFactory.java new file mode 100644 index 0000000..59bbcb8 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/update/UpdateLogicFactory.java @@ -0,0 +1,20 @@ +package com.gildedrose.update; + +import com.gildedrose.Item; + +public class UpdateLogicFactory { + public static UpdateLogic getUpdateLogic(Item item){ + switch (item.name) { + case "Aged Brie": + return new AgedBrie(); + case "Backstage passes to a TAFKAL80ETC concert": + return new BackstagePass(); + case "Sulfuras, Hand of Ragnaros": + return new Sulfuras(); + case "Conjured Mana Cake": + return new Conjured(); + default: + return new DefaultItem(); + } + } +}