replace sequential loop by loop on object

This commit is contained in:
brianblessou 2019-05-12 14:15:53 +02:00
parent 18f1fff052
commit 8b5693d77a
2 changed files with 28 additions and 27 deletions

View File

@ -8,55 +8,55 @@ class GildedRose {
} }
public void updateQuality() { public void updateQuality() {
for (int i = 0; i < items.length; i++) { for (Item item : items) {
if (!items[i].name.equals("Aged Brie") if (!item.name.equals("Aged Brie")
&& !items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { && !item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
if (items[i].quality > 0) { if (item.quality > 0) {
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
items[i].quality = items[i].quality - 1; item.quality = item.quality - 1;
} }
} }
} else { } else {
if (items[i].quality < 50) { if (item.quality < 50) {
items[i].quality = items[i].quality + 1; item.quality = item.quality + 1;
if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
if (items[i].sellIn < 11) { if (item.sellIn < 11) {
if (items[i].quality < 50) { if (item.quality < 50) {
items[i].quality = items[i].quality + 1; item.quality = item.quality + 1;
} }
} }
if (items[i].sellIn < 6) { if (item.sellIn < 6) {
if (items[i].quality < 50) { if (item.quality < 50) {
items[i].quality = items[i].quality + 1; item.quality = item.quality + 1;
} }
} }
} }
} }
} }
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
items[i].sellIn = items[i].sellIn - 1; item.sellIn = item.sellIn - 1;
} }
if (items[i].sellIn < 0) { if (item.sellIn < 0) {
if (!items[i].name.equals("Aged Brie")) { if (!item.name.equals("Aged Brie")) {
if (!items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { if (!item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
if (items[i].quality > 0) { if (item.quality > 0) {
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
items[i].quality = items[i].quality - 1; item.quality = item.quality - 1;
} }
} }
} else { } else {
items[i].quality = items[i].quality - items[i].quality; item.quality = item.quality - item.quality;
} }
} else { } else {
if (items[i].quality < 50) { if (item.quality < 50) {
items[i].quality = items[i].quality + 1; item.quality = item.quality + 1;
} }
} }
} }
} }
} }
} }

View File

@ -52,6 +52,7 @@ public class GildedRoseTest {
/** /**
* Execute n times the function update quality * Execute n times the function update quality
*
* @param numberOfTimes, number of times that you want to execute that function * @param numberOfTimes, number of times that you want to execute that function
*/ */
private void executeUpdateQuality(int numberOfTimes) { private void executeUpdateQuality(int numberOfTimes) {