Inventory.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. || items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
  11. //level 2 - quality
  12. if (items[i].getQuality() < 50) {
  13. increaseQualityBy1(items[i]);
  14. //level 3 - item type
  15. if (items[i].getName() == "Backstage passes to a TAFKAL80ETC concert") {
  16. //level 4 - sell in date
  17. if (items[i].getSellIn() < 11) {
  18. //level 5 - quality
  19. if (items[i].getQuality() < 50) {
  20. increaseQualityBy1(items[i]);
  21. }
  22. }
  23. //level 4 - sell in date
  24. if (items[i].getSellIn() < 6) {
  25. //level 5 - quality
  26. if (items[i].getQuality() < 50) {
  27. increaseQualityBy1(items[i]);
  28. }
  29. }
  30. }
  31. }
  32. //level 1 - item type
  33. } else {
  34. //level 2 - quality
  35. if (items[i].getQuality() > 0) {
  36. //level 3 - item type
  37. if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
  38. reduceQualityBy1(items[i]);
  39. }
  40. }
  41. }
  42. if(!items[i].getName().equals("Sulfuras, Hand of Ragnaros")){
  43. updateSellInDays(items[i]);
  44. }
  45. updateExpiredItems(items[i]);
  46. }
  47. }
  48. public void reduceQualityBy1(Item item){
  49. item.setQuality(item.getQuality() -1);
  50. }
  51. public void increaseQualityBy1(Item item){
  52. item.setQuality(item.getQuality() + 1);
  53. }
  54. public void setQualityTo0(Item item){
  55. item.setQuality(item.getQuality() - item.getQuality());
  56. }
  57. public void updateSellInDays(Item item){
  58. item.setSellIn(item.getSellIn() - 1);
  59. }
  60. public void updateExpiredItems(Item item){
  61. if (item.getSellIn() < 0) {
  62. //level 2 - item type
  63. if (item.getName().equals("Aged Brie")) {
  64. //level 3 - quality
  65. if (item.getQuality() < 50) {
  66. increaseQualityBy1(item);
  67. }
  68. //level 2 - item type
  69. } else if (item.getName().equals("Backstage passes to a TAFKAL80ETC concert")){
  70. setQualityTo0(item);
  71. //level 3 - item type
  72. } else {
  73. //level 4 - quality
  74. if (item.getQuality() > 0) {
  75. //level 5 - item type
  76. if (!item.getName().equals("Sulfuras, Hand of Ragnaros")) {
  77. reduceQualityBy1(item);
  78. }
  79. }
  80. }
  81. }
  82. }
  83. }