create two functions one for decrease and the other to increase quality

This commit is contained in:
brianblessou 2019-05-12 14:46:25 +02:00
parent cc1a3411d3
commit 733a05da12

View File

@ -7,6 +7,18 @@ class GildedRose {
this.items = items; this.items = items;
} }
private void increaseQuality(Item item) {
if (item.quality < 50) {
item.quality += 1;
}
}
private void decreaseQuality(Item item) {
if (item.quality > 0) {
item.quality -= 1;
}
}
public void updateQuality() { public void updateQuality() {
for (Item item : items) { for (Item item : items) {
if (item.name.equals("Sulfuras, Hand of Ragnaros")) { if (item.name.equals("Sulfuras, Hand of Ragnaros")) {
@ -15,27 +27,19 @@ class GildedRose {
if (!item.name.equals("Aged Brie") if (!item.name.equals("Aged Brie")
&& !item.name.equals("Backstage passes to a TAFKAL80ETC concert")) { && !item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
if (item.quality > 0) { decreaseQuality(item);
item.quality -= 1;
}
} else { } else {
if (item.quality < 50) { increaseQuality(item);
item.quality += 1;
if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) { if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
if (item.sellIn < 11) { if (item.sellIn < 11) {
if (item.quality < 50) { increaseQuality(item);
item.quality += 1;
}
} }
if (item.sellIn < 6) { if (item.sellIn < 6) {
if (item.quality < 50) { increaseQuality(item);
item.quality += 1;
}
}
} }
} }
} }
item.sellIn = item.sellIn - 1; item.sellIn = item.sellIn - 1;
@ -43,16 +47,12 @@ class GildedRose {
if (item.sellIn < 0) { if (item.sellIn < 0) {
if (!item.name.equals("Aged Brie")) { if (!item.name.equals("Aged Brie")) {
if (!item.name.equals("Backstage passes to a TAFKAL80ETC concert")) { if (!item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
if (item.quality > 0) { decreaseQuality(item);
item.quality -= 1;
}
} else { } else {
item.quality -= item.quality; item.quality -= item.quality;
} }
} else { } else {
if (item.quality < 50) { increaseQuality(item);
item.quality += 1;
}
} }
} }
} }