Mexi 8 лет назад
Родитель
Сommit
bd398ea410
4 измененных файлов: 59 добавлений и 30 удалений
  1. 34
    23
      Inventory.java
  2. 13
    0
      InventoryTest.java
  3. 2
    0
      Item.java
  4. 10
    7
      package.bluej

+ 34
- 23
Inventory.java Просмотреть файл

@@ -9,31 +9,42 @@ public class Inventory {
9 9
 
10 10
     public void updateQuality() {
11 11
         for (int i = 0; i < items.length; i++) {  
12
-            if (!items[i].getName().equals("Aged Brie")) {  //if item is not "Age Brie"
13
-                if (items[i].getQuality() > 0) {  //if item price >0
14
-                    if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) { //if item is not Sulfuras
15
-                        items[i].setQuality(items[i].getQuality() - 1); //item quality -1
16
-                    }
17
-                }
18
-            } else {
19
-                if (items[i].getQuality() < 50) { //if item quality <50
20
-                    items[i].setQuality(items[i].getQuality() + 1); //  quality = getQuality +1
21
-                }
12
+            String name = items[i].getName();
13
+            int quality = items[i].getQuality();
14
+            int sellIn = items[i].getSellIn();
15
+            if (quality >0 && quality < 50){
16
+                setQuality(name, quality,items[i], setSellIn(sellIn,items[i],name));
22 17
             }
18
+            
19
+        }
20
+        //cant be sulfuras
21
+    }
23 22
 
24
-            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) { // if item is not Sulfuras
25
-                items[i].setSellIn(items[i].getSellIn() - 1);  //sellin = sellin -1
23
+    public int setSellIn(int sellIn, Item items, String name){
24
+        sellIn = sellIn - 1;
25
+        items.setSellIn(sellIn);
26
+        int x = 0;
27
+        if (name.equals("conjured")|| sellIn <= 0){
28
+             x = 2;   //quality decrease by 1 when it hasn't passed the sellIn day;
29
+        } else if(sellIn > 0){ 
30
+             x = 1;  //quality decrease by 2 when it passed or on the pass day;
26 31
             }
32
+        return x;
33
+    }    // this is everything else
34
+   
27 35
 
28
-            if (items[i].getSellIn() < 0) {     //if sellin < 0 
29
-                if (!items[i].getName().equals("Aged Brie")) {  //if item is not "Age Brie"
30
-                  items[i].setQuality(items[i].getQuality() - 1); //item quality -1
31
-                } else {
32
-                    if (items[i].getQuality() < 50) {   
33
-                        items[i].setQuality(items[i].getQuality() + 1);
34
-                    }    // it is "Age Brie", quality = quality +1
35
-                }
36
-            }
36
+    public void setQuality(String name, int quality, Item items,int decrease){
37
+        if (name.equals("Aged Brie")){
38
+            quality =quality + decrease;
39
+            items.setQuality(quality);
37 40
         }
38
-}
39
-}
41
+        else{
42
+            quality = quality -decrease;
43
+            items.setQuality(quality);
44
+        }
45
+    }  // if this is Aged Brie
46
+
47
+
48
+    }
49
+
50
+

+ 13
- 0
InventoryTest.java Просмотреть файл

@@ -119,4 +119,17 @@ public class InventoryTest {
119 119
 
120 120
         assertEquals(expectedQuality, agedBrie.getQuality());
121 121
     }
122
+    
123
+    @Test
124
+    public void testUpdate_ForConjured() throws Exception {
125
+        
126
+        Item conjured = new Item("conjured", 4, 25);
127
+        int expectedQuality = conjured.getQuality() - 2;
128
+        Item[] items = {conjured};
129
+        Inventory sut = new Inventory(items);
130
+
131
+        sut.updateQuality();
132
+
133
+        assertEquals(expectedQuality, conjured.getQuality());
122 134
 }
135
+}

+ 2
- 0
Item.java Просмотреть файл

@@ -33,4 +33,6 @@ public class Item {
33 33
     public void setQuality(int quality) {
34 34
         this.quality = quality;
35 35
     }
36
+    
37
+    
36 38
 }

+ 10
- 7
package.bluej Просмотреть файл

@@ -5,21 +5,24 @@ dependency1.type=UsesDependency
5 5
 dependency2.from=InventoryTest
6 6
 dependency2.to=Inventory
7 7
 dependency2.type=UsesDependency
8
-editor.fx.0.height=709
9
-editor.fx.0.width=1175
10
-editor.fx.0.x=4
8
+dependency3.from=Inventory
9
+dependency3.to=Item
10
+dependency3.type=UsesDependency
11
+editor.fx.0.height=708
12
+editor.fx.0.width=1141
13
+editor.fx.0.x=260
11 14
 editor.fx.0.y=23
12 15
 objectbench.height=164
13 16
 objectbench.width=776
14 17
 package.divider.horizontal=0.6
15 18
 package.divider.vertical=0.6845018450184502
16 19
 package.editor.height=364
17
-package.editor.width=675
18
-package.editor.x=237
19
-package.editor.y=65
20
+package.editor.width=674
21
+package.editor.x=120
22
+package.editor.y=56
20 23
 package.frame.height=600
21 24
 package.frame.width=800
22
-package.numDependencies=2
25
+package.numDependencies=3
23 26
 package.numTargets=3
24 27
 package.showExtends=true
25 28
 package.showUses=true