1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. public class Inventory {
  2. private Item[] items;
  3. public Inventory(Item[] items) {
  4. super();
  5. this.items = items;
  6. }
  7. public void updatedBrie(int i){
  8. if(items[i].getSellIn() > 0 && items[i].getQuality() <= 49){
  9. items[i].setQuality(items[i].getQuality() + 1);
  10. } else if (items[i].getSellIn() < 0 && items[i].getQuality() <= 49){
  11. items[i].setQuality(items[i].getQuality() + 2);
  12. }
  13. }
  14. public void updatedRegularItem(int i){
  15. if(items[i].getSellIn() > 0 && items[i].getQuality() > 0){
  16. items[i].setQuality(items[i].getQuality() - 1);
  17. } else if (items[i].getSellIn() < 0 && items[i].getQuality() > 1){
  18. items[i].setQuality(items[i].getQuality() - 2);
  19. }
  20. }
  21. public void updatedCounjuredItem(int i){
  22. if(items[i].getSellIn() > 0 && items[i].getQuality() > 0){
  23. items[i].setQuality(items[i].getQuality() - 2);
  24. } else if(items[i].getSellIn() > 0 && items[i].getQuality() > 1){
  25. items[i].setQuality(items[i].getQuality() - 4);
  26. }
  27. }
  28. public void updateQuality() {
  29. for (int i = 0; i < items.length; i++) {
  30. if (items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
  31. continue;
  32. }
  33. if (items[i].getName().equals("Aged Brie")) {
  34. updatedBrie(i);
  35. } else if (items[i].getName().equals("Conjured Mage Water")){
  36. updatedCounjuredItem(i);
  37. } else{updatedRegularItem(i);}
  38. if (items[i].getQuality() < 80){
  39. items[i].setSellIn(items[i].getSellIn() - 1);
  40. }
  41. }
  42. }
  43. }