Eric Foster 6 yıl önce
ebeveyn
işleme
c9ce97759b
2 değiştirilmiş dosya ile 57 ekleme ve 53 silme
  1. 43
    39
      Inventory.java
  2. 14
    14
      InventoryTest.java

+ 43
- 39
Inventory.java Dosyayı Görüntüle

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

+ 14
- 14
InventoryTest.java Dosyayı Görüntüle

@@ -24,7 +24,7 @@ public class InventoryTest {
24 24
         Item[] items = {sulfuras};
25 25
         Inventory sut = new Inventory(items);
26 26
 
27
-        sut.updateQuality();
27
+        sut.updateInventory();
28 28
 
29 29
         assertEquals(expectedQuality, sulfuras.getQuality());
30 30
     }
@@ -34,7 +34,7 @@ public class InventoryTest {
34 34
         Item[] items = {sulfuras};
35 35
         Inventory sut = new Inventory(items);
36 36
 
37
-        sut.updateQuality();
37
+        sut.updateInventory();
38 38
 
39 39
         assertEquals(expectedSellIn, sulfuras.getSellIn());
40 40
     }
@@ -45,7 +45,7 @@ public class InventoryTest {
45 45
         Item[] items = {normalItem};
46 46
         Inventory sut = new Inventory(items);
47 47
 
48
-        sut.updateQuality();
48
+        sut.updateInventory();
49 49
 
50 50
         assertEquals(expectedSellIn, normalItem.getSellIn());
51 51
     }
@@ -56,7 +56,7 @@ public class InventoryTest {
56 56
         Item[] items = {normalItem};
57 57
         Inventory sut = new Inventory(items);
58 58
 
59
-        sut.updateQuality();
59
+        sut.updateInventory();
60 60
 
61 61
         assertEquals(expectedQuality, normalItem.getQuality());
62 62
     }
@@ -68,7 +68,7 @@ public class InventoryTest {
68 68
         Item[] items = {normalItemWithMinimumQuality};
69 69
         Inventory sut = new Inventory(items);
70 70
 
71
-        sut.updateQuality();
71
+        sut.updateInventory();
72 72
 
73 73
         assertEquals(minimumQuality, normalItemWithMinimumQuality.getQuality());
74 74
     }
@@ -80,7 +80,7 @@ public class InventoryTest {
80 80
         Item[] items = {normalItemWithPassedSellDate};
81 81
         Inventory sut = new Inventory(items);
82 82
 
83
-        sut.updateQuality();
83
+        sut.updateInventory();
84 84
 
85 85
         assertEquals(expectedQuality, normalItemWithPassedSellDate.getQuality());
86 86
     }
@@ -92,7 +92,7 @@ public class InventoryTest {
92 92
         Item[] items = {agedBrie};
93 93
         Inventory sut = new Inventory(items);
94 94
 
95
-        sut.updateQuality();
95
+        sut.updateInventory();
96 96
 
97 97
         assertEquals(expectedQuality, agedBrie.getQuality());
98 98
     }
@@ -103,7 +103,7 @@ public class InventoryTest {
103 103
         Item[] items = {agedBrie};
104 104
         Inventory sut = new Inventory(items);
105 105
 
106
-        sut.updateQuality();
106
+        sut.updateInventory();
107 107
 
108 108
         assertEquals(MAX_QUALITY, agedBrie.getQuality());
109 109
     }
@@ -115,7 +115,7 @@ public class InventoryTest {
115 115
         Item[] items = {agedBrie};
116 116
         Inventory sut = new Inventory(items);
117 117
 
118
-        sut.updateQuality();
118
+        sut.updateInventory();
119 119
 
120 120
         assertEquals(expectedQuality, agedBrie.getQuality());
121 121
     }
@@ -126,7 +126,7 @@ public class InventoryTest {
126 126
         Item[] items = {backStagePass};
127 127
         Inventory sut = new Inventory(items);
128 128
 
129
-        sut.updateQuality();
129
+        sut.updateInventory();
130 130
 
131 131
         assertEquals(0, backStagePass.getQuality());
132 132
     }
@@ -138,7 +138,7 @@ public class InventoryTest {
138 138
         Item[] items = {backStagePass};
139 139
         Inventory sut = new Inventory(items);
140 140
 
141
-        sut.updateQuality();
141
+        sut.updateInventory();
142 142
 
143 143
         assertEquals(21, backStagePass.getQuality());
144 144
     }
@@ -150,7 +150,7 @@ public class InventoryTest {
150 150
         Item[] items = {backStagePass};
151 151
         Inventory sut = new Inventory(items);
152 152
 
153
-        sut.updateQuality();
153
+        sut.updateInventory();
154 154
 
155 155
         assertEquals(expectedQuality, backStagePass.getQuality());
156 156
     }
@@ -162,7 +162,7 @@ public class InventoryTest {
162 162
         Item[] items = {backStagePass};
163 163
         Inventory sut = new Inventory(items);
164 164
 
165
-        sut.updateQuality();
165
+        sut.updateInventory();
166 166
 
167 167
         assertEquals(expectedQuality, backStagePass.getQuality());
168 168
     }
@@ -176,7 +176,7 @@ public class InventoryTest {
176 176
         Item[] items = {backStagePassMoreThan10DaysAway, backStagePass10DaysAway, backStagePass5DaysAway};
177 177
         Inventory sut = new Inventory(items);
178 178
 
179
-        sut.updateQuality();
179
+        sut.updateInventory();
180 180
 
181 181
         assertEquals(MAX_QUALITY, backStagePassMoreThan10DaysAway.getQuality());
182 182
         assertEquals(MAX_QUALITY, backStagePass10DaysAway.getQuality());