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

Done #42

Open
wants to merge 1 commit into
base: testing
Choose a base branch
from
Open

Done #42

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
166 changes: 107 additions & 59 deletions src/fi/oulu/tol/sqat/GildedRose.java
Original file line number Diff line number Diff line change
@@ -1,98 +1,146 @@
package fi.oulu.tol.sqat;

import java.util.ArrayList;
import java.util.List;
import java.util.Collections;


public class GildedRose {

private static List<Item> items = null;
private static ArrayList<Item> items = null;

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

public void addItem(Item item) {
items.add(item);
}
/**
* @param args
*/
public static void main(String[] args) {

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));

public GildedRose() {
items = new ArrayList<Item>();
}
public static void updateEndOfDay()
updateQuality();
}



public static void updateQuality()
{
for (int i = 0; i < items.size(); i++)
//for (int i = 0; i < items.size(); i++)

for(Item item:items)
{
if ((!"Aged Brie".equals(items.get(i).getName())) && !"Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName()))
if (("Aged Brie".equals(item.getName())) || "Backstage passes to a TAFKAL80ETC concert".equals(item.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);
}
}
if (item.getQuality() < 50)
{
item.increaseQuality();

if ("Backstage passes to a TAFKAL80ETC concert".equals(item.getName()))
{
if (item.getSellIn() < 11)
{
if (item.getQuality() < 50)
{
item.increaseQuality();
}
}

if (item.getSellIn() < 6)
{
if (item.getQuality() < 50)
{
item.increaseQuality();
}
}
}
}
}
else
{
if (items.get(i).getQuality() < 50)
if (item.getQuality() > 0)

{
items.get(i).setQuality(items.get(i).getQuality() + 1);

if ("Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName()))
if (!"Sulfuras, Hand of Ragnaros".equals(item.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);
}
}
item.decreaseQuality();
}
}
}

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

if (items.get(i).getSellIn() < 0)
if (item.getSellIn() < 0)
{
if (!"Aged Brie".equals(items.get(i).getName()))
if ("Aged Brie".equals(item.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

if (item.getQuality() < 50)
{
items.get(i).setQuality(items.get(i).getQuality() - items.get(i).getQuality());
item.increaseQuality();
}

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

}
}
}
}
}



public void addItem(Item item) {
// TODO Auto-generated method stub


try {
items.add(item);
} catch (NullPointerException e) {
// TODO Auto-generated catch block

items = new ArrayList<Item>();
items.add(item);
}

}



public void updateEndOfDay() {
// TODO Auto-generated method stub
updateQuality();

}



public ArrayList<Item> getItems() {
// TODO Auto-generated method stub
ArrayList <Item> rItems =items;
Collections.reverse(rItems);
return rItems;
}

}
31 changes: 27 additions & 4 deletions src/fi/oulu/tol/sqat/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@


public class Item {
String name;
int sellIn;
int quality;
public String name;
public int sellIn;
public int quality;

public Item(String name, int sellIn, int quality) {
this.setName(name);
Expand All @@ -31,5 +31,28 @@ public int getQuality() {
public void setQuality(int quality) {
this.quality = quality;
}
}

public void decreaseQuality(){
this.quality--;

}
public void increaseQuality(){
this.quality++;

}
public void decreaseSellIn(){
this.sellIn--;

}
public boolean isExpired(){
return (this.sellIn==0);
}

public boolean hasReachedMaximumQuality(){
return (this.quality==50);
}

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