|
@@ -1,80 +1,95 @@
|
1
|
1
|
package com.zipcodewilmington.gildedrose;
|
2
|
2
|
|
3
|
3
|
|
|
4
|
+import com.sun.tools.javac.jvm.Items;
|
|
5
|
+
|
4
|
6
|
public class Inventory {
|
|
7
|
+
|
5
|
8
|
private static Item[] items;
|
6
|
9
|
|
7
|
10
|
public Inventory(Item[] items) {
|
8
|
11
|
|
9
|
12
|
super();
|
10
|
|
- this.items = items;
|
|
13
|
+
|
|
14
|
+ Inventory.items = items;
|
11
|
15
|
}
|
12
|
16
|
|
|
17
|
+ public void updateQuality(Item[] items) {
|
13
|
18
|
|
14
|
|
- public static void updateQuality() {
|
|
19
|
+ for (Item item : items) {
|
15
|
20
|
|
16
|
|
- for (int i = 0; i < items.length; i++) {
|
|
21
|
+ String name = item.getName();
|
17
|
22
|
|
18
|
|
- if (!items[i].getName().equals("Aged Brie")
|
19
|
|
- && !items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
|
|
23
|
+ int sellin = item.getSellIn();
|
20
|
24
|
|
21
|
|
- if (items[i].getQuality() > 0) {
|
|
25
|
+ int quality = item.getQuality();
|
22
|
26
|
|
23
|
|
- if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
|
24
|
|
- items[i].setQuality(items[i].getQuality() - 1);
|
25
|
|
- }
|
26
|
|
- }
|
27
|
|
- } else {
|
|
27
|
+ if (quality >= 0 || quality <= 50) {
|
28
|
28
|
|
29
|
|
- if (items[i].getQuality() < 50) {
|
30
|
|
- items[i].setQuality(items[i].getQuality() + 1);
|
|
29
|
+ setQuality(name, item, quality, setSellIn(name, sellin, item));
|
31
|
30
|
|
32
|
|
- if (items[i].getName() == "Backstage passes to a TAFKAL80ETC concert") {
|
|
31
|
+ }
|
33
|
32
|
|
34
|
|
- if (items[i].getSellIn() < 11) {
|
|
33
|
+ }
|
|
34
|
+ }
|
35
|
35
|
|
36
|
|
- if (items[i].getQuality() < 50) {
|
37
|
|
- items[i].setQuality(items[i].getQuality() + 1);
|
38
|
|
- }
|
39
|
|
- }
|
|
36
|
+ public void setQuality(String name, Item item, int quality, int sellinAdjustment) {
|
40
|
37
|
|
41
|
|
- if (items[i].getSellIn() < 6) {
|
|
38
|
+ if (name.equals("Aged Brie")) {
|
42
|
39
|
|
43
|
|
- if (items[i].getQuality() < 50) {
|
44
|
|
- items[i].setQuality(items[i].getQuality() + 1);
|
45
|
|
- }
|
46
|
|
- }
|
47
|
|
- }
|
48
|
|
- }
|
49
|
|
- }
|
|
40
|
+ item.setQuality(quality + sellinAdjustment);
|
50
|
41
|
|
51
|
|
- if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
|
52
|
|
- items[i].setSellIn(items[i].getSellIn() - 1);
|
53
|
|
- }
|
|
42
|
+ } else if (name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
54
|
43
|
|
55
|
|
- if (items[i].getSellIn() < 0) {
|
|
44
|
+ setQualityForPasses(item,quality);
|
|
45
|
+ } else {
|
56
|
46
|
|
57
|
|
- if (!items[i].getName().equals("Aged Brie")) {
|
|
47
|
+ item.setQuality(quality - sellinAdjustment);
|
|
48
|
+ }
|
58
|
49
|
|
59
|
|
- if (!items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
|
60
|
50
|
|
61
|
|
- if (items[i].getQuality() > 0) {
|
|
51
|
+ }
|
62
|
52
|
|
63
|
|
- if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
|
64
|
|
- items[i].setQuality(items[i].getQuality() - 1);
|
65
|
|
- }
|
66
|
|
- }
|
67
|
|
- } else {
|
|
53
|
+ public int setSellIn(String name, int sellin, Item item) {
|
68
|
54
|
|
69
|
|
- items[i].setQuality(0);
|
70
|
|
- }
|
71
|
|
- } else {
|
|
55
|
+ int newSellin = sellin - 1;
|
|
56
|
+
|
|
57
|
+ item.setSellIn(newSellin);
|
|
58
|
+
|
|
59
|
+ int sellinAdjustment = (newSellin <= 0) ? 2 : 1;
|
|
60
|
+
|
|
61
|
+ return sellinAdjustment;
|
72
|
62
|
|
73
|
|
- if (items[i].getQuality() < 50) {
|
74
|
|
- items[i].setQuality(items[i].getQuality() + 1);
|
75
|
|
- }
|
76
|
|
- }
|
77
|
|
- }
|
78
|
|
- }
|
79
|
63
|
}
|
80
|
|
-}
|
|
64
|
+
|
|
65
|
+ public void setQualityForPasses(Item item, int quality) {
|
|
66
|
+
|
|
67
|
+ int sellin = item.getSellIn();
|
|
68
|
+
|
|
69
|
+ int newSellin = sellin - 1;
|
|
70
|
+
|
|
71
|
+ item.setSellIn(newSellin);
|
|
72
|
+
|
|
73
|
+ if(newSellin <= 0) {
|
|
74
|
+
|
|
75
|
+ item.setQuality(quality + 2);
|
|
76
|
+
|
|
77
|
+ }else if (newSellin <= 5) {
|
|
78
|
+
|
|
79
|
+ item.setQuality(quality + 3);
|
|
80
|
+
|
|
81
|
+ }else if (newSellin <= 10) {
|
|
82
|
+
|
|
83
|
+ item.setQuality(quality + 2);
|
|
84
|
+
|
|
85
|
+ }else{
|
|
86
|
+
|
|
87
|
+ item.setQuality(quality + 1);
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+}
|
|
91
|
+
|
|
92
|
+}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|