123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. public class Inventory {
  2. private Item[] items;
  3. public Inventory(Item[] items) {
  4. super();
  5. this.items = items;
  6. }
  7. public void updateQuality() {
  8. for (int i = 0; i < items.length; i++) { // each if/else handles each specific item
  9. if (items[i].getName().equals("Sulfuras, Hand of Ragnoros")) {
  10. continue;
  11. }
  12. if (items[i].getName().equals("Aged Brie")) {
  13. updateAgedBrie(i);
  14. } else updateNormalItem(i);
  15. }
  16. }
  17. public void updateAgedBrie(int i) {
  18. if (items[i].getSellIn() > 0 && items[i].getQuality() <= 49) {
  19. items[i].setQuality(items[i].getQuality() + 1);
  20. } else if (items[i].getSellIn() <= 0 && items[i].getQuality() <= 48) {
  21. items[i].setQuality(items[i].getQuality() + 2);
  22. }
  23. }
  24. public void updateNormalItem(int i) {
  25. if (items[i].getSellIn() > 0 && items[i].getQuality() <= 49) {
  26. items[i].setQuality(items[i].getQuality() - 1);
  27. } else if (items[i].getSellIn() <= 0 && items[i].getQuality() <= 48) {
  28. items[i].setQuality(items[i].getQuality() - 2);
  29. }
  30. }
  31. public void updateConjuredItem(int i) {
  32. if (items[i].getSellIn() > 0 && items[i].getQuality() <= 50){
  33. items[i].setQuality(items[i].getQuality() - 1);
  34. }
  35. if (items[i].getSellIn() <= 0 && items[i].getQuality() <= 50){
  36. items[i].setQuality(items[i].getQuality() - 4);
  37. }
  38. }
  39. }