create backstage Passes class

Override the methods from StorageItem to the sub class backstage Passes
This commit is contained in:
Trobax 2022-11-23 17:48:06 +01:00
parent 77fca57da8
commit 025c3e4a9a
2 changed files with 31 additions and 16 deletions

View File

@ -0,0 +1,25 @@
package com.gildedrose;
public class BackstagePasses extends StorageItem {
public BackstagePasses(Item item) {
super(item);
}
@Override
protected void updateQuality() {
increaseQuality();
if (item.sellIn < 11) {
increaseQuality();
}
if (item.sellIn < 6) {
increaseQuality();
}
}
@Override
protected void updateExpired() {
item.quality = 0;
}
}

View File

@ -4,11 +4,13 @@ public class StorageItem {
public static final String AGED_BRIE = "Aged Brie";
public static final String BACKSTAGE_PASSES = "Backstage passes to a TAFKAL80ETC concert";
public static final String SULFURAS = "Sulfuras, Hand of Ragnaros";
private Item item;
protected Item item;
public static StorageItem createItem(Item item) {
if (item.name.equals(AGED_BRIE)){
if (item.name.equals(AGED_BRIE)) {
return new AgeddBrie(item);
} else if (item.name.equals(BACKSTAGE_PASSES)) {
return new BackstagePasses(item);
}
return new StorageItem(item);
}
@ -26,17 +28,7 @@ public class StorageItem {
}
protected void updateQuality() {
if (item.name.equals(BACKSTAGE_PASSES)) {
increaseQuality();
if (item.sellIn < 11) {
increaseQuality();
}
if (item.sellIn < 6) {
increaseQuality();
}
} else if (item.name.equals(SULFURAS)) {
if (item.name.equals(SULFURAS)) {
return;
} else decreaseQuality();
}
@ -53,9 +45,7 @@ public class StorageItem {
}
protected void updateExpired() {
if (item.name.equals(BACKSTAGE_PASSES)) {
item.quality = 0;
} else if (item.name.equals(SULFURAS)) {
if (item.name.equals(SULFURAS)) {
return;
} else {
decreaseQuality();