Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment finished #57

Open
wants to merge 3 commits into
base: refactoring
Choose a base branch
from
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
Empty file.
Empty file.
Empty file.
Empty file.
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/tests/GildedRoseTest.class
Binary file not shown.
176 changes: 101 additions & 75 deletions src/fi/oulu/tol/sqat/GildedRose.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,101 +7,127 @@
public class GildedRose {

private static List<Item> items = null;

private static final String DEXTERITY_VEST_NAME = "+5 Dexterity Vest";
private static final String AGED_BRIE_NAME = "Aged Brie";
private static final String MONGOOSE_ELIXIR_NAME = "Elixir of the Mongoose";
private static final String SULFURAS_NAME = "Sulfuras, Hand of Ragnaros";
private static final String BACKSTAGE_PASSES_NAME = "Backstage passes to a TAFKAL80ETC concert";
private static final String MANA_CAKE_NAME = "Conjured Mana Cake";

private int currentItemQuality;
private String currentItemName;
private int currentItemSellIn;

/**
* @param args
*/
public static void main(String[] args) {
GildedRose gildedRose = new GildedRose();

System.out.println("OMGHAI!");

items = new ArrayList<Item>();
items.add(new Item("+5 Dexterity Vest", 10, 20));
items.add(new Item("Aged Brie", 2, 0));
items.add(new Item("Elixir of the Mongoose", 5, 7));
items.add(new Item("Sulfuras, Hand of Ragnaros", 0, 80));
items.add(new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20));
items.add(new Item("Conjured Mana Cake", 3, 6));
items.add(new Item(DEXTERITY_VEST_NAME, 10, 20));
items.add(new Item(AGED_BRIE_NAME, 2, 0));
items.add(new Item(MONGOOSE_ELIXIR_NAME, 5, 7));
items.add(new Item(SULFURAS_NAME, 0, 80));
items.add(new Item(BACKSTAGE_PASSES_NAME, 15, 20));
items.add(new Item(MANA_CAKE_NAME, 3, 6));

updateQuality();
gildedRose.updateEndOfDay();
}

public List<Item> getItems() {
return items;
}

public void addItem(Item item) {
items.add(item);
}

public GildedRose() {
items = new ArrayList<Item>();
}

public static void updateQuality()
public 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()))
{
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
{
if (items.get(i).getQuality() < 50)
{
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);
}
}
currentItemQuality = items.get(i).getQuality();
currentItemSellIn = items.get(i).getSellIn();
currentItemName = items.get(i).getName();

if (items.get(i).getSellIn() < 6)
{
if (items.get(i).getQuality() < 50)
{
items.get(i).setQuality(items.get(i).getQuality() + 1);
}
}
}
}
}
updateSellIn();
updateItemQualities();

items.get(i).setQuality(currentItemQuality);
items.get(i).setSellIn(currentItemSellIn);
}
}

if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName()))
{
items.get(i).setSellIn(items.get(i).getSellIn() - 1);
}
private void updateSellIn() {
if (!SULFURAS_NAME.equals(currentItemName))
currentItemSellIn--;
}

private void updateItemQualities() {
switch (currentItemName) {
case AGED_BRIE_NAME:
updateAgedBrieQuality();
break;
case BACKSTAGE_PASSES_NAME:
updateBackstagePassesQuality();
break;
case SULFURAS_NAME:
break;
default:
updateNormalItemQuality();
};
}

private void updateAgedBrieQuality() {
incrementQuality();

if (sellInPassed())
incrementQuality();
}

private void updateBackstagePassesQuality() {
if (sellInPassed()) {
setQuality(0);
return;
}

incrementQuality();

if (currentItemSellIn < 11)
incrementQuality();

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);
}
}
}
}
if (currentItemSellIn < 6)
incrementQuality();
}

private void updateNormalItemQuality() {
decrementQuality();
}

private void incrementQuality() {
if (currentItemQuality < 50)
currentItemQuality++;
}

private void decrementQuality() {
if (currentItemQuality > 0)
currentItemQuality--;
}

private void setQuality(int newQuality) {
currentItemQuality = newQuality;
}

private boolean sellInPassed() {
return currentItemSellIn < 0;
}

}
Loading