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