diff --git a/Java-Approvals/src/main/java/com/gildedrose/GildedRose.java b/Java-Approvals/src/main/java/com/gildedrose/GildedRose.java index 89bb6fd7..82b1e1bd 100644 --- a/Java-Approvals/src/main/java/com/gildedrose/GildedRose.java +++ b/Java-Approvals/src/main/java/com/gildedrose/GildedRose.java @@ -1,9 +1,6 @@ package com.gildedrose; class GildedRose { - private final static String AGED_BRIE = "Aged Brie"; - private final static String BACKSTAGE_PASSES = "Backstage passes to a TAFKAL80ETC concert"; - private final static String SULFURAS = "Sulfuras, Hand of Ragnaros"; Item[] items; @@ -13,66 +10,26 @@ class GildedRose { public void updateQuality() { for (Item item : items) { - if (item.name.equals(AGED_BRIE)) { - increaseQualityByOne(item); - } else if (item.name.equals(BACKSTAGE_PASSES)) { - increaseQualityBackstage(item); + if (item.name.equals(Item.AGED_BRIE)) { + item.increaseQualityByOne(); + } else if (item.name.equals(Item.BACKSTAGE_PASSES)) { + item.increaseQualityBackstage(); } else { - decreaseQualityByOne(item); + item.decreaseQualityByOne(); } - decreaseSellInEachDay(item); + item.decreaseSellInEachDay(); if (item.sellIn < 0) { - if (item.name.equals(AGED_BRIE)) { - increaseQualityByOne(item); - } else if (item.name.equals(BACKSTAGE_PASSES)) { + if (item.name.equals(Item.AGED_BRIE)) { + item.increaseQualityByOne(); + } else if (item.name.equals(Item.BACKSTAGE_PASSES)) { item.quality = 0; } else { - decreaseQualityByOne(item); + item.decreaseQualityByOne(); } } } } - private void decreaseSellInEachDay(Item item) { - if (!item.name.equals(SULFURAS)) { - item.sellIn--; - } - } - - private void increaseQualityBackstage(Item item) { - if (item.sellIn < 6) { - increaseQualityByThree(item); - } else if (item.sellIn < 11) { - increaseQualityByTwo(item); - } else { - increaseQualityByOne(item); - } - } - - private void decreaseQualityByOne(Item item) { - if (item.quality > 0) { - if (!item.name.equals(SULFURAS)) { - item.quality--; - } - } - } - - private void increaseQualityByOne(Item item) { - if (item.quality < 50) { - item.quality++; - } - } - - private void increaseQualityByTwo(Item item) { - increaseQualityByOne(item); - increaseQualityByOne(item); - } - - private void increaseQualityByThree(Item item) { - increaseQualityByTwo(item); - increaseQualityByOne(item); - } - } diff --git a/Java-Approvals/src/main/java/com/gildedrose/Item.java b/Java-Approvals/src/main/java/com/gildedrose/Item.java index 465729ec..e188b535 100644 --- a/Java-Approvals/src/main/java/com/gildedrose/Item.java +++ b/Java-Approvals/src/main/java/com/gildedrose/Item.java @@ -2,6 +2,9 @@ package com.gildedrose; public class Item { + public final static String AGED_BRIE = "Aged Brie"; + public final static String BACKSTAGE_PASSES = "Backstage passes to a TAFKAL80ETC concert"; + public final static String SULFURAS = "Sulfuras, Hand of Ragnaros"; public String name; public int sellIn; @@ -18,4 +21,44 @@ public class Item { public String toString() { return this.name + ", " + this.sellIn + ", " + this.quality; } + + void decreaseSellInEachDay() { + if (!name.equals(SULFURAS)) { + sellIn--; + } + } + + void increaseQualityByOne() { + if (quality < 50) { + quality++; + } + } + + void increaseQualityByTwo() { + increaseQualityByOne(); + increaseQualityByOne(); + } + + void increaseQualityByThree() { + increaseQualityByTwo(); + increaseQualityByOne(); + } + + void decreaseQualityByOne() { + if (quality > 0) { + if (!name.equals(SULFURAS)) { + quality--; + } + } + } + + void increaseQualityBackstage() { + if (sellIn < 6) { + increaseQualityByThree(); + } else if (sellIn < 11) { + increaseQualityByTwo(); + } else { + increaseQualityByOne(); + } + } }