Przeglądaj źródła

demetrm - complete

Demetrius Murray 6 lat temu
rodzic
commit
93e9955cf6

+ 27
- 42
src/main/java/com/zipcodewilmington/gildedrose/Inventory.java Wyświetl plik

@@ -9,56 +9,41 @@ public class Inventory {
9 9
         this.items = items;
10 10
     }
11 11
 
12
-
13 12
     public void updateQuality() {
14
-        /*
15
-        loop through items.
16
-
17
-        1. if name DNE "Aged" && DNE "Backstage
18
-            a. if quality > 0
19
-                1. if name is NOT "Sulfuras",  subtract 1 quality | *
20
-        2. If name is either "Aged" or "Backstage"
21
-            a. if quality < 50, add 1 quality | **
22
-                1. if name is "Backstage"
23
-                    a. if getSellIn < 11
24
-                        1. if quality < 50, then add 1 quality | *
25
-                    b. if get sellIn < 6
26
-                        1. if quality < 50, then add 1 quality | *
27
-        1. if name DNE "Sulfuras"
28
-            a. subtract one sellIn | **
29
-
30
-        1. If getSellIn < 0
31
-            a. if name is NOT "Aged"
32
-                1. if name is NOT "Backstage"
33
-                    a. if quality > 0
34
-                        1. if name is NOT "Sulfuras, then subtract 1 quality (useless);
35
-                2. else set quality to 0;
36
-            b. else if quality < 50, add 1 quality
37
-         */
38 13
         for (int i = 0; i < items.length; i++) {
39
-            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
40
-                if (items[i].getQuality() < 50) {
41
-                    items[i].setQuality(items[i].getQuality() + 1);
42
-                    if (items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
43
-                        if (items[i].getSellIn() < 11) {
14
+            String name = items[i].getName();
15
+            int quality = items[i].getQuality();
16
+            if(!name.equals("Sulfuras, Hand of Ragnaros")) {
17
+                switch (name) {
18
+                    case "Conjured":
19
+                        items[i].setQuality(quality - 2);
20
+                        break;
21
+                    case "Backstage passes to a TAFKAL80ETC concert":
22
+                        items[i].setQuality(items[i].getQuality() + 1);
23
+                        if (items[i].getSellIn() < 0) {
24
+                            items[i].setQuality(0);
25
+                        } else if (items[i].getSellIn() < 6 && quality < 50) {
26
+                            items[i].setQuality(items[i].getQuality() + 2);
27
+                        } else if (items[i].getSellIn() < 11 && quality < 50) {
44 28
                             items[i].setQuality(items[i].getQuality() + 1);
45 29
                         }
46
-                        if (items[i].getSellIn() < 6) {
30
+                        break;
31
+                    case "Aged Brie":
32
+                        if (quality < 50){
47 33
                             items[i].setQuality(items[i].getQuality() + 1);
34
+                            if (items[i].getSellIn() < 0) {
35
+                                items[i].setQuality(items[i].getQuality() + 1);
36
+                            }
48 37
                         }
49
-                    }
50
-                }
51
-
52
-                items[i].setSellIn(items[i].getSellIn() - 1);
53
-
54
-                if (items[i].getSellIn() < 0) {
55
-                    if (items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
56
-                        items[i].setQuality(0);
57
-                    } else if (items[i].getName().equals("Aged Brie") && items[i].getQuality() < 50) {
58
-                        items[i].setQuality(items[i].getQuality() + 1);
59
-                    }
38
+                        break;
39
+                    default:
40
+                        if (quality < 50) {
41
+                            items[i].setQuality(items[i].getQuality() - 1);
42
+                        }
43
+                        break;
60 44
                 }
61 45
             }
46
+            items[i].setSellIn(items[i].getSellIn() - 1);
62 47
         }
63 48
     }
64 49
 }