Inventory.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. public class Inventory {
  2. private Item[] items;
  3. public Inventory(Item[] items) {
  4. super();
  5. this.items = items;
  6. }
  7. public void updateInventory() {
  8. for (int i = 0; i < items.length; i++) {
  9. if(items[i].getName().equals("Sulfuras, Hand of Ragnaros")){
  10. break;
  11. } else {
  12. updateQuality(items[i]);
  13. updateSellInDays(items[i]);
  14. if (items[i].getSellIn() < 0) {
  15. updateExpiredItems(items[i]);
  16. }
  17. }
  18. }
  19. }
  20. public void updateQuality(Item item){
  21. if (item.getName().equals("Aged Brie") ||
  22. item.getName().equals("Backstage passes to a TAFKAL80ETC concert")){
  23. updateQualityForAgedItems(item);
  24. } else if (item.getQuality() > 0) {
  25. reduceQualityBy1(item);
  26. }
  27. }
  28. public void updateQualityForAgedItems(Item item){
  29. if (item.getName().equals("Aged Brie") && item.getQuality() < 50) {
  30. increaseQualityBy1(item);
  31. } else if (item.getName().equals("Backstage passes to a TAFKAL80ETC concert") &&
  32. item.getQuality() < 50){
  33. increaseQualityBy1(item);
  34. if (item.getSellIn() < 11 && item.getQuality() < 50) {
  35. increaseQualityBy1(item);
  36. }
  37. if (item.getSellIn() < 6 && item.getQuality() < 50) {
  38. increaseQualityBy1(item);
  39. }
  40. }
  41. }
  42. public void updateSellInDays(Item item){
  43. item.setSellIn(item.getSellIn() - 1);
  44. }
  45. public void updateExpiredItems(Item item){
  46. if (item.getName().equals("Aged Brie") && item.getQuality() < 50) {
  47. increaseQualityBy1(item);
  48. } else if (item.getName().equals("Backstage passes to a TAFKAL80ETC concert")){
  49. setQualityTo0(item);
  50. } else if (item.getQuality() > 0) {
  51. reduceQualityBy1(item);
  52. }
  53. }
  54. public void reduceQualityBy1(Item item){
  55. item.setQuality(item.getQuality() -1);
  56. }
  57. public void increaseQualityBy1(Item item){
  58. item.setQuality(item.getQuality() + 1);
  59. }
  60. public void setQualityTo0(Item item){
  61. item.setQuality(item.getQuality() - item.getQuality());
  62. }
  63. }