Inventory.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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("Backstage passes to a TAFKAL80ETC concert")){
  10. increaseQualityByOne(i);
  11. increaseQualityForBackstagePasses(i);
  12. }else if(items[i].getName().equals("Aged Brie")){
  13. increaseQualityByOne(i);
  14. }else{
  15. if (items[i].getQuality() > 0) {
  16. if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
  17. items[i].setQuality(items[i].getQuality() - 1);
  18. }
  19. }
  20. }
  21. if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
  22. items[i].setSellIn(items[i].getSellIn() - 1);
  23. }
  24. if (items[i].getSellIn() < 0) {
  25. if (!items[i].getName().equals("Aged Brie")) {
  26. if (!items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
  27. if (items[i].getQuality() > 0) {
  28. if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
  29. items[i].setQuality(items[i].getQuality() - 1);
  30. }
  31. }
  32. } else {
  33. items[i].setQuality(items[i].getQuality()
  34. - items[i].getQuality());
  35. }
  36. } else {
  37. increaseQualityByOne(i);
  38. }
  39. }
  40. }
  41. }
  42. public void increaseQualityByOne(int i){
  43. if(items[i].getQuality() < 50){
  44. items[i].setQuality(items[i].getQuality() + 1);
  45. }
  46. }
  47. public void increaseQualityForBackstagePasses(int i){
  48. if(items[i].getSellIn() < 11) {
  49. increaseQualityByOne(i);
  50. }
  51. if(items[i].getSellIn() < 6){
  52. increaseQualityByOne(i);
  53. }
  54. }
  55. }