Inventory.java 1.2KB

123456789101112131415161718192021222324252627282930313233343536
  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 {
  19. if(items[i].getSellIn() > 0 && items[i].getQuality() > 0){
  20. items[i].setQuality(items[i].getQuality() - 1);
  21. }
  22. if(items[i].getSellIn() <= 0 && items[i].getQuality() > 0){
  23. items[i].setQuality(items[i].getQuality() - 2);}
  24. }
  25. if(items[i].getQuality() < 80){
  26. items[i].setSellIn(items[i].getSellIn() - 1);
  27. }
  28. }
  29. }
  30. }