Skip to content

Commit

Permalink
commit 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeonkyujin committed Oct 30, 2024
1 parent 4f86cf4 commit 99dc6fc
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 24 additions & 1 deletion .idea/networking1~2.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 8 additions & 13 deletions Java/src/main/java/com/gildedrose/AgedBrieItem.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package com.gildedrose;

public class AgedBrieItem implements UpdatingItem {
private Item item;
public class AgedBrieItem extends UpdateItem {
private final Item item;

public AgedBrieItem(Item item) {
this.item = item;
}

@Override
public void updateQuality() {
if (item.sellIn > 0) {
item.quality += 1;
if (item.quality > 50) {
item.quality = 50;
}
} else {
item.quality += 2;
if (item.quality > 50) {
item.quality = 50;
}
increaseQuality(item);
if (item.sellIn < 0) {
increaseQuality(item);
}
item.sellIn -= 1;
fixQuality(item);
decreaseSellIn(item);
}

}


Expand Down
22 changes: 10 additions & 12 deletions Java/src/main/java/com/gildedrose/BackStageItem.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gildedrose;

public class BackStageItem implements UpdatingItem {
public class BackStageItem extends UpdateItem {
private Item item;

public BackStageItem(Item item) {
Expand All @@ -9,20 +9,18 @@ public BackStageItem(Item item) {

@Override
public void updateQuality() {
increaseQuality(item);
if (item.sellIn <= 10) {
increaseQuality(item);
}
if (item.sellIn <= 5) {
increaseQuality(item);
}
if (item.sellIn == 0) {
item.quality = 0;
} else if (item.sellIn <= 5) {
item.quality += 3;
if (item.quality > 50) {
item.quality = 50;
}
} else if (item.sellIn <= 10) {
item.quality += 2;
if (item.quality > 50) {
item.quality = 50;
}
}
item.sellIn -= 1;
fixQuality(item);
decreaseSellIn(item);
}
}

15 changes: 6 additions & 9 deletions Java/src/main/java/com/gildedrose/CommonItem.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gildedrose;

public class CommonItem implements UpdatingItem {
public class CommonItem extends UpdateItem {

private Item item;

Expand All @@ -10,14 +10,11 @@ public CommonItem(Item item) {

@Override
public void updateQuality() {
if (item.quality > 0 && item.sellIn > 0) {
item.quality -= 1;
} else if (item.quality > 0 && item.sellIn < 0) {
item.quality -= 2;
if (item.quality < 0) {
item.quality = 0;
}
decreaseQuality(item);
if (item.sellIn < 0) {
decreaseQuality(item);
}
item.sellIn -= 1;
fixQuality(item);
decreaseSellIn(item);
}
}
18 changes: 6 additions & 12 deletions Java/src/main/java/com/gildedrose/ConjuredItem.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gildedrose;

public class ConjuredItem implements UpdatingItem {
public class ConjuredItem extends UpdateItem {
private Item item;

public ConjuredItem(Item item) {
Expand All @@ -9,18 +9,12 @@ public ConjuredItem(Item item) {

@Override
public void updateQuality() {
if (item.sellIn > 0) {
item.quality -= 2;
if (item.quality < 0) {
item.quality = 0;
}
} else {
item.quality -= 4;
if (item.quality < 0) {
item.quality = 0;
}
doubleDecreaseQuality(item);
if (item.sellIn < 0) {
doubleDecreaseQuality(item);
}
item.sellIn -= 1;
fixQuality(item);
decreaseSellIn(item);
}
}

6 changes: 3 additions & 3 deletions Java/src/main/java/com/gildedrose/GildedRose.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
class GildedRose {
Item[] items;

UpdatingItem[] updatingItems;
UpdateItem[] updatingItems;

public GildedRose(Item[] items) {
this.items = items;
this.updatingItems = new UpdatingItem[items.length];
this.updatingItems = new UpdateItem[items.length];
for (int i = 0; i < items.length; i++) {
if (items[i].name.equals("Aged Brie")) {
updatingItems[i] = new AgedBrieItem(items[i]);
Expand All @@ -24,7 +24,7 @@ public GildedRose(Item[] items) {
}

public void updateQuality() {
for (UpdatingItem item : updatingItems) {
for (UpdateItem item : updatingItems) {
item.updateQuality();

}
Expand Down
3 changes: 1 addition & 2 deletions Java/src/main/java/com/gildedrose/SulfurasItem.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gildedrose;

public class SulfurasItem implements UpdatingItem {
public class SulfurasItem extends UpdateItem {
private Item item;

public SulfurasItem(Item item) {
Expand All @@ -9,7 +9,6 @@ public SulfurasItem(Item item) {

@Override
public void updateQuality() {

}
}

30 changes: 30 additions & 0 deletions Java/src/main/java/com/gildedrose/UpdateItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.gildedrose;

public abstract class UpdateItem {
protected void decreaseSellIn(Item item) {
item.sellIn -= 1;
}

protected void increaseQuality(Item item) {
item.quality += 1;
}

protected void decreaseQuality(Item item) {
item.quality -= 1;
}

protected void doubleDecreaseQuality(Item item) {
item.quality -= 2;
}

protected void fixQuality(Item item) {
if (item.quality > 50) {
item.quality = 50;
}
if (item.quality < 0) {
item.quality = 0;
}
}

protected abstract void updateQuality();
}
6 changes: 0 additions & 6 deletions Java/src/main/java/com/gildedrose/UpdatingItem.java

This file was deleted.

0 comments on commit 99dc6fc

Please sign in to comment.