Last active
June 17, 2019 07:00
-
-
Save cmh114933/c8c5c4b2c61f20e52017bb5538407bc3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Kinds of item | |
- all items | |
- max quality is 50, other than legendary | |
1. Legendary | |
- before expiry -> doesn't change quality | |
- after expiry -> doesn't change quality | |
2 conjured | |
- before expiry -> quality decreases x2 | |
- after expiry -> quality decrease x4 | |
3 normal | |
- before expiry -> quality decreases x1 | |
- after expiry -> quality decrease x2 | |
4 agedBrie | |
- before expiry -> quality increase x1 | |
- after expiry -> quality increase x2 | |
5 backstagePass | |
- before expiry -> | |
- sellIn > 10 -> quality increase x1 | |
- sellIn <= 10 -> quality increase x2 | |
- after expiry -> quality = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GildedRose { | |
Item[] items; | |
public GildedRose(Item[] items) { | |
this.items = items; | |
} | |
public boolean isAgedBrie(Item item){ | |
return item.name.equals("Aged Brie"); | |
} | |
public boolean isBackstagePass(Item item){ | |
return item.name.equals("Backstage passes to a TAFKAL80ETC concert"); | |
} | |
public boolean isSulfuras(Item item){ | |
return item.name.equals("Sulfuras, Hand of Ragnaros"); | |
} | |
public boolean isConjured(Item item){ | |
return item.name.startsWith("Conjured"); | |
} | |
public void incrementQuality(Item item){ | |
if (item.quality < 50) { | |
item.quality += 1; | |
} | |
} | |
public void decrementQuality(Item item){ | |
if (item.quality > 0) { | |
item.quality -= 1; | |
} | |
} | |
public void updateQuality() { | |
for (int i = 0; i < items.length; i++) { | |
Item item = items[i]; | |
if (!isAgedBrie(item) && !isBackstagePass(item)) { | |
if (!isSulfuras(item)) { | |
decrementQuality(item); | |
if(isConjured(item)){ | |
decrementQuality(item); | |
} | |
} | |
} else { | |
incrementQuality(item); | |
if (isBackstagePass(item)) { | |
if (items[i].sellIn < 11) { | |
incrementQuality(item); | |
} | |
if (items[i].sellIn < 6) { | |
incrementQuality(item); | |
} | |
} | |
} | |
if (!isSulfuras(item)) { | |
items[i].sellIn = items[i].sellIn - 1; | |
} | |
if (items[i].sellIn < 0) { | |
if(isAgedBrie(item)){ | |
incrementQuality(item); | |
} else if (isBackstagePass(item)){ | |
item.quality = 0; | |
} else if(isSulfuras(item)){ | |
} else { | |
decrementQuality(item); | |
if(isConjured(item)){ | |
decrementQuality(item); | |
} | |
} | |
} | |
} | |
} | |
public static void main(String[] args) { | |
Item[] items = { | |
new Item("Aged Brie", 3, 35), | |
new Item("Sulfuras, Hand of Ragnaros", 0, 80), | |
new Item("Backstage passes to a TAFKAL80ETC concert", 12, 30), | |
new Item("Backstage passes to a TAFKAL80ETC concert", 7, 30), | |
new Item("Backstage passes to a TAFKAL80ETC concert", 2, 30), | |
new Item("Cake", 3, 10), | |
new Item("Conjured Cake", 3, 10) | |
}; | |
GildedRose inn = new GildedRose(items); | |
for(int day = 0; day < 8; day++){ | |
System.out.println("Day " + day); | |
Item[] listOfItems = inn.items; | |
System.out.println("Name , SellIn , Quality"); | |
for(Item item: listOfItems){ | |
System.out.println(item.name + " , " + item.sellIn + " , " + item.quality); | |
} | |
System.out.println("-----------------------------"); | |
inn.updateQuality(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment