Seth 6 years ago
parent
commit
d2d135da10

+ 90
- 1
src/main/java/com/zipcodewilmington/gildedrose/Inventory.java View File

@@ -3,6 +3,9 @@ package com.zipcodewilmington.gildedrose;
3 3
 
4 4
 public class Inventory {
5 5
     private Item[] items;
6
+    private final String brie = "Aged Brie";
7
+    private final String pass = "Backstage passes to a TAFKAL80ETC concert";
8
+    private final String hand = "Sulfuras, Hand of Ragnaros";
6 9
 
7 10
     public Inventory(Item[] items) {
8 11
         super();
@@ -12,6 +15,92 @@ public class Inventory {
12 15
 
13 16
     public void updateQuality() {
14 17
         for (int i = 0; i < items.length; i++) {
18
+            switch (items[i].getName()){
19
+
20
+                case brie :
21
+
22
+                    increaseQuality5(items[i]);
23
+                    sellOne(items[i]);
24
+                    justUnder6(items[i]);
25
+                    betterWithAge(items[i]);
26
+                    break;
27
+
28
+                case pass :
29
+
30
+                    increaseQuality5(items[i]);
31
+                    sellOne(items[i]);
32
+                    justUnder11(items[i]);
33
+                    justUnder6(items[i]);
34
+                    soldOut(items[i]);
35
+                    break;
36
+
37
+                case hand :
38
+
39
+                    increaseQuality5(items[i]);
40
+                    soldOut(items[i]);
41
+                    break;
42
+
43
+                default :
44
+
45
+                    //soldOut(items[i]);
46
+                    expiring(items[i]);
47
+
48
+            }
49
+
50
+        }
51
+    }
52
+
53
+
54
+    public void increaseQuality5(Item item) {
55
+        if(item.getQuality() < 50 && item.getQuality() > 0){
56
+            item.setQuality(item.getQuality()+1);
57
+
58
+        }
59
+    }
60
+
61
+    public void sellOne(Item item) {
62
+
63
+        item.setSellIn(item.getSellIn() - 1);
64
+    }
65
+
66
+    public void betterWithAge(Item item) {
67
+        if (item.getSellIn() < 0) {
68
+            item.setQuality(item.getQuality() + 1);
69
+        }
70
+    }
71
+
72
+    public void justUnder11(Item item) {
73
+        if (item.getSellIn() < 11 && item.getQuality() < 50) {
74
+            item.setQuality(item.getQuality() + 1);
75
+        }
76
+
77
+    }
78
+
79
+    public void justUnder6(Item item) {
80
+        if (item.getSellIn() < 6 && item.getQuality() < 50) {
81
+            item.setQuality(item.getQuality() + 1);
82
+
83
+        }
84
+
85
+    }
86
+
87
+    public void soldOut(Item item) {
88
+        if (item.getSellIn() < 0) {
89
+            item.setQuality(item.getQuality() - item.getQuality());
90
+        }
91
+
92
+    }
93
+
94
+    public void expiring(Item item) {
95
+        if (item.getQuality() > 0) {
96
+            item.setQuality(item.getQuality() - 1);
97
+
98
+        }
99
+
100
+    }
101
+
102
+}
103
+        /*for (int i = 0; i < items.length; i++) {
15 104
             if (!items[i].getName().equals("Aged Brie")
16 105
                     && !items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
17 106
                 if (items[i].getQuality() > 0) {
@@ -63,4 +152,4 @@ public class Inventory {
63 152
             }
64 153
         }
65 154
     }
66
-}
155
+}*/

+ 31
- 16
src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java View File

@@ -100,7 +100,7 @@ public class InventoryTest {
100 100
 
101 101
     @Test
102 102
     public void brieTest01() {
103
-        Item item = new Item("Aged Brie", 12, 20);
103
+        Item item = new Item("Aged Brie", 11, 20);
104 104
         Item[] items = {item};
105 105
         Inventory inv = new Inventory(items);
106 106
 
@@ -114,7 +114,7 @@ public class InventoryTest {
114 114
 
115 115
     @Test
116 116
     public void brieTest02() {
117
-        Item item = new Item("Aged Brie", -1, 20);
117
+        Item item = new Item("Aged Brie", 6, 20);
118 118
         Item[] items = {item};
119 119
         Inventory inv = new Inventory(items);
120 120
 
@@ -127,6 +127,20 @@ public class InventoryTest {
127 127
     }
128 128
 
129 129
     @Test
130
+    public void brieTest03() {
131
+        Item item = new Item("Aged Brie", -1, 20);
132
+        Item[] items = {item};
133
+        Inventory inv = new Inventory(items);
134
+
135
+        int expected = 23;
136
+        inv.updateQuality();
137
+        int actual = item.getQuality();
138
+
139
+        Assert.assertEquals(actual, expected);
140
+
141
+    }
142
+
143
+    @Test
130 144
     public void otherTest01() {
131 145
         Item item = new Item("Goop", 5, 20);
132 146
         Item[] items = {item};
@@ -141,6 +155,20 @@ public class InventoryTest {
141 155
     }
142 156
 
143 157
     @Test
158
+    public void otherTest02() {
159
+        Item item = new Item("Goop", -1, 20);
160
+        Item[] items = {item};
161
+        Inventory inv = new Inventory(items);
162
+
163
+        int expected = 19;
164
+        inv.updateQuality();
165
+        int actual = item.getQuality();
166
+
167
+        Assert.assertEquals(expected, actual);
168
+
169
+    }
170
+
171
+    @Test
144 172
     public void backStageTest01() {
145 173
         Item item = new Item("Backstage passes to a TAFKAL80ETC concert", 12, 20);
146 174
         Item[] items = {item};
@@ -198,22 +226,9 @@ public class InventoryTest {
198 226
 
199 227
     }
200 228
 
201
-    @Test
202
-    public void otherTest02() {
203
-        Item item = new Item("Goop", -1, 20);
204
-        Item[] items = {item};
205
-        Inventory inv = new Inventory(items);
206
-
207
-        int expected = 18;
208
-        inv.updateQuality();
209
-        int actual = item.getQuality();
210
-
211
-        Assert.assertEquals(expected, actual);
212
-
213
-    }
214 229
 
215 230
     @Test
216
-    public void sulfurasTest01() {
231
+    public void backStageTest04() {
217 232
         Item item = new Item("Backstage passes to a TAFKAL80ETC concert", -1, 10);
218 233
         Item[] items = {item};
219 234
         Inventory inv = new Inventory(items);