Inventory.java 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. //level 3 - item type
  29. if (item.getName() == "Backstage passes to a TAFKAL80ETC concert") {
  30. //level 4 - sell in date
  31. if (item.getSellIn() < 11) {
  32. //level 5 - quality
  33. if (item.getQuality() < 50) {
  34. increaseQualityBy1(item);
  35. }
  36. }
  37. //level 4 - sell in date
  38. if (item.getSellIn() < 6) {
  39. //level 5 - quality
  40. if (item.getQuality() < 50) {
  41. increaseQualityBy1(item);
  42. }
  43. }
  44. }
  45. }
  46. //level 1 - item type
  47. } else if (item.getQuality() > 0) {
  48. reduceQualityBy1(item);
  49. }
  50. }
  51. public void updateSellInDays(Item item){
  52. item.setSellIn(item.getSellIn() - 1);
  53. }
  54. public void updateExpiredItems(Item item){
  55. if (item.getName().equals("Aged Brie") && item.getQuality() < 50) {
  56. increaseQualityBy1(item);
  57. } else if (item.getName().equals("Backstage passes to a TAFKAL80ETC concert")){
  58. setQualityTo0(item);
  59. } else if (item.getQuality() > 0) {
  60. reduceQualityBy1(item);
  61. }
  62. }
  63. public void reduceQualityBy1(Item item){
  64. item.setQuality(item.getQuality() -1);
  65. }
  66. public void increaseQualityBy1(Item item){
  67. item.setQuality(item.getQuality() + 1);
  68. }
  69. public void setQualityTo0(Item item){
  70. item.setQuality(item.getQuality() - item.getQuality());
  71. }
  72. }