Inventory.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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(Item item : items) {
  9. if(item.getName().startsWith("Sulfuras")) {
  10. continue; // Doesnt have to be sold or decrease in quality
  11. }
  12. int curQuality = item.getQuality();
  13. int qualityChange = item.getName().equals("Aged Brie") ? 1 : -1;
  14. qualityChange *= item.getSellIn() < 1 ? 2 : 1;
  15. int newQuality = curQuality + qualityChange;
  16. if(newQuality < 0)
  17. newQuality = 0;
  18. if(newQuality > 50)
  19. newQuality = 50;
  20. item.setQuality(newQuality);
  21. item.setSellIn(item.getSellIn() - 1);
  22. }
  23. }
  24. }
  25. /* public void updateQuality() {
  26. for (int i = 0; i < items.length; i++) {
  27. if (!items[i].getName().equals("Aged Brie")) {
  28. if (items[i].getQuality() > 0) {
  29. if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
  30. items[i].setQuality(items[i].getQuality() - 1);
  31. }
  32. }
  33. } else {
  34. if (items[i].getQuality() < 50) {
  35. items[i].setQuality(items[i].getQuality() + 1);
  36. }
  37. }
  38. if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
  39. items[i].setSellIn(items[i].getSellIn() - 1);
  40. }
  41. if (items[i].getSellIn() < 0) {
  42. if (!items[i].getName().equals("Aged Brie")) {
  43. items[i].setQuality(items[i].getQuality() - 1);
  44. } else {
  45. if (items[i].getQuality() < 50) {
  46. items[i].setQuality(items[i].getQuality() + 1);
  47. }
  48. }
  49. }
  50. }
  51. }
  52. }*/