From 519eb43d5f0d0682658b395459504c4d58d377eb Mon Sep 17 00:00:00 2001 From: villanibe Date: Thu, 26 Jun 2025 15:05:44 +0200 Subject: [PATCH] creating constants --- .../main/java/com/gildedrose/GildedRose.java | 68 ++++++++++++------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/Java/src/main/java/com/gildedrose/GildedRose.java b/Java/src/main/java/com/gildedrose/GildedRose.java index 87a3b926..05e89dde 100644 --- a/Java/src/main/java/com/gildedrose/GildedRose.java +++ b/Java/src/main/java/com/gildedrose/GildedRose.java @@ -1,6 +1,16 @@ package com.gildedrose; class GildedRose { + + public static final String AGED_BRIE = "Aged Brie"; + public static final String BACKSTAGE_PASSES = "Backstage passes to a TAFKAL80ETC concert"; + public static final String SULFURAS = "Sulfuras, Hand of Ragnaros"; + public static final int QUALITY_LEVEL_0 = 0; + public static final int QUALITY_LEVEL_50 = 50; + public static final int SELL_IN_DAY11 = 11; + public static final int SELL_IN_DAY6 = 6; + public static final int SELL_IN_DAY0 = 0; + Item[] items; public GildedRose(Item[] items) { @@ -8,52 +18,58 @@ class GildedRose { } public void updateQuality() { - for (int i = 0; i < items.length; i++) { - if (!items[i].name.equals("Aged Brie") - && !items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { - if (items[i].quality > 0) { - if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { - items[i].quality = items[i].quality - 1; + for (Item item : items) { + // processing quality + if (!item.name.equals(AGED_BRIE) && !item.name.equals(BACKSTAGE_PASSES)) { + if (item.quality > QUALITY_LEVEL_0) { + if (!item.name.equals(SULFURAS)) { + item.quality = item.quality - 1; } } } else { - if (items[i].quality < 50) { - items[i].quality = items[i].quality + 1; + // processing quality + if (item.quality < QUALITY_LEVEL_50) { + item.quality = item.quality + 1; - if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { - if (items[i].sellIn < 11) { - if (items[i].quality < 50) { - items[i].quality = items[i].quality + 1; + // processing sell date + if (item.name.equals(BACKSTAGE_PASSES)) { + + if (item.sellIn < SELL_IN_DAY11) { + if (item.quality < QUALITY_LEVEL_50) { + item.quality = item.quality + 1; } } - if (items[i].sellIn < 6) { - if (items[i].quality < 50) { - items[i].quality = items[i].quality + 1; + if (item.sellIn < SELL_IN_DAY6) { + if (item.quality < QUALITY_LEVEL_50) { + item.quality = item.quality + 1; } } } } } - if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { - items[i].sellIn = items[i].sellIn - 1; + // processing sell date + if (!item.name.equals(SULFURAS)) { + item.sellIn = item.sellIn - 1; } - if (items[i].sellIn < 0) { - if (!items[i].name.equals("Aged Brie")) { - if (!items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { - if (items[i].quality > 0) { - if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { - items[i].quality = items[i].quality - 1; + // processing sell date + if (item.sellIn < SELL_IN_DAY0) { + if (!item.name.equals(AGED_BRIE)) { + if (!item.name.equals(BACKSTAGE_PASSES)) { + // processing quality + if (item.quality > QUALITY_LEVEL_0) { + if (!item.name.equals(SULFURAS)) { + item.quality = item.quality - 1; } } } else { - items[i].quality = items[i].quality - items[i].quality; + item.quality = QUALITY_LEVEL_0; } } else { - if (items[i].quality < 50) { - items[i].quality = items[i].quality + 1; + if (item.quality < QUALITY_LEVEL_50) { + item.quality = item.quality + 1; } } }