Inventory.java 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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++) {
  9. if(items[i].getName().equals("Aged Brie")){
  10. if(items[i].getQuality() < 50){
  11. items[i].setQuality(items[i].getQuality() + 1);
  12. }
  13. if(items[i].getSellIn() < 0 && items[i].getQuality() < 50){
  14. items[i].setQuality(items[i].getQuality() + 1);
  15. }
  16. } else if(items[i].getName().equals("Sulfuras, Hand of Ragnaros")){
  17. items[i].setQuality(items[i].getQuality() + 0);
  18. } else if(items[i].getName().equals("Conjured Sword")){
  19. if(items[i].getSellIn() > 0 && items[i].getQuality() > 0){
  20. items[i].setQuality(items[i].getQuality() - 2);
  21. }
  22. if(items[i].getSellIn() <= 0 && items[i].getQuality() > 0){
  23. items[i].setQuality(items[i].getQuality() - 4);
  24. }
  25. }else {
  26. if(items[i].getSellIn() > 0 && items[i].getQuality() > 0){
  27. items[i].setQuality(items[i].getQuality() - 1);
  28. }
  29. if(items[i].getSellIn() <= 0 && items[i].getQuality() > 0){
  30. items[i].setQuality(items[i].getQuality() - 2);
  31. }
  32. }
  33. if(items[i].getQuality() < 80){
  34. items[i].setSellIn(items[i].getSellIn() - 1);
  35. }
  36. }
  37. }
  38. }