Inventory.java 2.8KB

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