instance method

This commit is contained in:
Karim Fadel 2026-01-14 08:38:43 +02:00
parent da6f6ffd5b
commit 4a96b36ac3
2 changed files with 29 additions and 25 deletions

View File

@ -11,31 +11,7 @@ class GildedRose {
public void updateQuality() { public void updateQuality() {
for (Item item : items) { for (Item item : items) {
if (item.isAgedBrie()) { item.updateQuality();
item.increaseQualityByOne();
item.decreaseSellInEachDay();
if (item.sellIn < 0) {
item.increaseQualityByOne();
}
} else if (item.isBackstagePasses()) {
item.increaseQualityBackstage();
item.decreaseSellInEachDay();
if (item.sellIn < 0) {
item.quality = 0;
}
} else {
item.decreaseQualityByOne();
item.decreaseSellInEachDay();
if (item.sellIn < 0) {
item.decreaseQualityByOne();
}
}
} }
} }

View File

@ -17,6 +17,34 @@ public class Item {
this.quality = quality; this.quality = quality;
} }
public void updateQuality() {
if (isAgedBrie()) {
increaseQualityByOne();
decreaseSellInEachDay();
if (sellIn < 0) {
increaseQualityByOne();
}
} else if (isBackstagePasses()) {
increaseQualityBackstage();
decreaseSellInEachDay();
if (sellIn < 0) {
quality = 0;
}
} else {
decreaseQualityByOne();
decreaseSellInEachDay();
if (sellIn < 0) {
decreaseQualityByOne();
}
}
}
public boolean isBackstagePasses() { public boolean isBackstagePasses() {
return name.equals(BACKSTAGE_PASSES); return name.equals(BACKSTAGE_PASSES);
} }