Inventory.java 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. //This loop runs at the end of each day
  10. //SellIn is the value which denotes the number of days we have to sell the item
  11. //Quality value denotes how values for every item
  12. if (item.getName().equals("Aged Brie")) {
  13. if (item.getQuality() < 50) {
  14. item.setQuality(item.getQuality() + 1);
  15. }
  16. if (item.getSellIn() < 0 && item.getQuality() < 50) {
  17. item.setQuality(item.getQuality() + 1);
  18. }
  19. } else {
  20. if (item.getQuality() > 0) {
  21. if (!item.getName().equals("Sulfuras, Hand of Ragnaros")) {
  22. item.setQuality(item.getQuality() - 1);
  23. }
  24. }
  25. if (item.getSellIn() < 0) {
  26. item.setQuality(item.getQuality() - 1);
  27. }
  28. }
  29. if (!item.getName().equals("Sulfuras, Hand of Ragnaros")) {
  30. item.setSellIn(item.getSellIn() - 1);
  31. }
  32. }
  33. }
  34. private boolean isNotLegenday(Item item){
  35. return item.getName().equals("Sulfuras, Hand of Ragnaros") ? true : false;
  36. }
  37. }