Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/fi/
Binary file modified bin/fi/oulu/tol/sqat/GildedRose.class
Binary file not shown.
Binary file modified bin/fi/oulu/tol/sqat/Item.class
Binary file not shown.
Binary file modified bin/fi/oulu/tol/sqat/tests/GildedRoseTest.class
Binary file not shown.
134 changes: 72 additions & 62 deletions src/fi/oulu/tol/sqat/GildedRose.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

public class GildedRose {

private static final String SULFURAS_HAND_OF_RAGNAROS = "Sulfuras, Hand of Ragnaros";
private static final String AGED_BRIE = "Aged Brie";
private static final String BACKSTAGE_PASSES_TO_A_TAFKAL80ETC_CONCERT = "Backstage passes to a TAFKAL80ETC concert";
private static List<Item> items = null;

public List<Item> getItems() {
Expand All @@ -19,80 +22,87 @@ public void addItem(Item item) {
public GildedRose() {
items = new ArrayList<Item>();
}
public static void updateEndOfDay()
{
for (int i = 0; i < items.size(); i++)
{
if ((!"Aged Brie".equals(items.get(i).getName())) && !"Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName()))

public static void updateEndOfDay() {

for(Item item:items)
{
String itemName = item.getName();

if ((isAgedBrie(itemName)) || isTAFKAL80ETC_BackStagePass(itemName))
{
if (items.get(i).getQuality() > 0)
if (!item.reachedMaxiumQuality())
{
if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName()))
{
items.get(i).setQuality(items.get(i).getQuality() - 1);
}
item.increaseQuality();

if (isTAFKAL80ETC_BackStagePass(itemName))
handleBackStagePass(item);
}

}
else
{
if (items.get(i).getQuality() < 50)
if (!item.hasZeroQuality())
{
items.get(i).setQuality(items.get(i).getQuality() + 1);

if ("Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName()))
{
if (items.get(i).getSellIn() < 11)
{
if (items.get(i).getQuality() < 50)
{
items.get(i).setQuality(items.get(i).getQuality() + 1);
}
}

if (items.get(i).getSellIn() < 6)
{
if (items.get(i).getQuality() < 50)
{
items.get(i).setQuality(items.get(i).getQuality() + 1);
}
}
}
if (!isSulfurasHandOfRagnaros(itemName))
item.decreaseQuality();
}
}

if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName()))
{
items.get(i).setSellIn(items.get(i).getSellIn() - 1);
}
if (!isSulfurasHandOfRagnaros(itemName))
item.decreaseSellIn();

if (items.get(i).getSellIn() < 0)
{
if (!"Aged Brie".equals(items.get(i).getName()))
{
if (!"Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName()))
{
if (items.get(i).getQuality() > 0)
{
if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName()))
{
items.get(i).setQuality(items.get(i).getQuality() - 1);
}
}
}
else
{
items.get(i).setQuality(items.get(i).getQuality() - items.get(i).getQuality());
}
}
else
{
if (items.get(i).getQuality() < 50)
{
items.get(i).setQuality(items.get(i).getQuality() + 1);
}
}
}
handleItemExpired(item);
}
}


private static void handleBackStagePass(Item item) {

if (item.getSellIn() < 11 && !item.reachedMaxiumQuality())
item.increaseQuality();


if (item.getSellIn() < 6 && !item.reachedMaxiumQuality())
item.increaseQuality();
}

private static void handleItemExpired(Item item) {

String itemName = item.getName();
if (item.isExpired())
{
if (isAgedBrie(itemName))
{
if (!item.reachedMaxiumQuality())
item.increaseQuality();
}
else
{
if (isTAFKAL80ETC_BackStagePass(itemName))
{
item.setQuality(0);
}
else
{
if (!item.hasZeroQuality() && !isSulfurasHandOfRagnaros(itemName))
item.decreaseQuality();

}
}
}
}

private static boolean isSulfurasHandOfRagnaros(String itemName) {
return SULFURAS_HAND_OF_RAGNAROS.equals(itemName);
}

private static boolean isAgedBrie(String itemName) {
return AGED_BRIE.equals(itemName);
}

private static boolean isTAFKAL80ETC_BackStagePass(String itemName) {
return BACKSTAGE_PASSES_TO_A_TAFKAL80ETC_CONCERT.equals(itemName);
}

}
32 changes: 32 additions & 0 deletions src/fi/oulu/tol/sqat/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,54 @@ public Item(String name, int sellIn, int quality) {
this.setQuality(quality);
}

public boolean reachedMaxiumQuality() {
return quality >= 50;
}

public boolean hasZeroQuality() {
return quality == 0;
}

// Past date of sellIn
public boolean isExpired() {
return sellIn < 0;
}

public void decreaseQuality() {
quality--;
if(quality < 0)
quality = 0;
}

public void increaseQuality() {
quality++;
}

public void decreaseSellIn() {
sellIn--;
}

/* Generated getter and setter code */
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getSellIn() {
return sellIn;
}

public void setSellIn(int sellIn) {
this.sellIn = sellIn;
}

public int getQuality() {
return quality;
}

public void setQuality(int quality) {
this.quality = quality;
}
Expand Down
Loading