Inventory.java 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. if (item.getQuality() < 50) {
  23. increaseQualityBy1(item);
  24. }
  25. } else if (item.getName().equals("Backstage passes to a TAFKAL80ETC concert")){
  26. if (item.getQuality() < 50) {
  27. increaseQualityBy1(item);
  28. }
  29. if (item.getSellIn() < 11 && item.getQuality() < 50) {
  30. increaseQualityBy1(item);
  31. }
  32. if (item.getSellIn() < 6 && item.getQuality() < 50) {
  33. increaseQualityBy1(item);
  34. }
  35. } else if (item.getQuality() > 0) {
  36. reduceQualityBy1(item);
  37. }
  38. }
  39. public void updateSellInDays(Item item){
  40. item.setSellIn(item.getSellIn() - 1);
  41. }
  42. public void updateExpiredItems(Item item){
  43. if (item.getName().equals("Aged Brie") && item.getQuality() < 50) {
  44. increaseQualityBy1(item);
  45. } else if (item.getName().equals("Backstage passes to a TAFKAL80ETC concert")){
  46. setQualityTo0(item);
  47. } else if (item.getQuality() > 0) {
  48. reduceQualityBy1(item);
  49. }
  50. }
  51. public void reduceQualityBy1(Item item){
  52. item.setQuality(item.getQuality() -1);
  53. }
  54. public void increaseQualityBy1(Item item){
  55. item.setQuality(item.getQuality() + 1);
  56. }
  57. public void setQualityTo0(Item item){
  58. item.setQuality(item.getQuality() - item.getQuality());
  59. }
  60. }