Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[신예진] 1차 과제 제출 #12

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Java/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion Java/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
57 changes: 8 additions & 49 deletions Java/src/main/java/com/gildedrose/GildedRose.java
Original file line number Diff line number Diff line change
@@ -1,62 +1,21 @@
package com.gildedrose;

import com.gildedrose.update.UpdateLogic;
import com.gildedrose.update.UpdateLogicFactory;

class GildedRose {
Item[] items;
UpdateLogicFactory updateLogicFactory;

public GildedRose(Item[] items) {
this.items = items;
updateLogicFactory = new UpdateLogicFactory();
}

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;
}
}
} else {
if (items[i].quality < 50) {
items[i].quality = items[i].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;
}
}

if (items[i].sellIn < 6) {
if (items[i].quality < 50) {
items[i].quality = items[i].quality + 1;
}
}
}
}
}

if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
items[i].sellIn = items[i].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;
}
}
} else {
items[i].quality = items[i].quality - items[i].quality;
}
} else {
if (items[i].quality < 50) {
items[i].quality = items[i].quality + 1;
}
}
}
for (Item item : items) {
UpdateLogic updateLogic = updateLogicFactory.getUpdateLogic(item);
updateLogic.update(item);
Comment on lines +16 to +18
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존 for문을 향상된 for문으로 수정하여 가독성이 좋아진 것 같네요👍

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

import static com.gildedrose.update.ItemConstants.*;

import com.gildedrose.Item;

public class AgedBrie extends UpdateLogic {

@Override
public void update(Item item) {

increaseQuality(item, DEFAULT_QUALITY_INCREMENT);
decreaseSellIn(item);

if (item.sellIn < QUALITY_MIN) {
increaseQuality(item, DEFAULT_QUALITY_INCREMENT);
}
}
}
33 changes: 33 additions & 0 deletions Java/src/main/java/com/gildedrose/update/BackstagePass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.gildedrose.update;

import static com.gildedrose.update.ItemConstants.*;

import com.gildedrose.Item;

public class BackstagePass extends UpdateLogic {

private static final int BACKSTAGE_SELL_IN_THRESHOLD_10 = 10;
private static final int BACKSTAGE_SELL_IN_THRESHOLD_5 = 5;

@Override
public void update(Item item) {

// 판매 기한이 10일 이하일 때 품질 1 증가
if (item.sellIn <= BACKSTAGE_SELL_IN_THRESHOLD_10) {
increaseQuality(item, DEFAULT_QUALITY_INCREMENT);
}

// 판매 기한이 5일 이하일 때 추가로 품질 1 증가
if (item.sellIn <= BACKSTAGE_SELL_IN_THRESHOLD_5) {
increaseQuality(item, DEFAULT_QUALITY_INCREMENT);
}

// 판매 기한 1일 감소
decreaseSellIn(item);

// 판매 기한이 지난 경우 품질을 0으로 설정
if (item.sellIn < QUALITY_MIN) {
item.quality = QUALITY_MIN;
}
}
}
25 changes: 25 additions & 0 deletions Java/src/main/java/com/gildedrose/update/Conjured.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.gildedrose.update;

import static com.gildedrose.update.ItemConstants.*;

import com.gildedrose.Item;

public class Conjured extends UpdateLogic {

@Override
public void update(Item item) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저의 품질 감소 로직보다 훨씬 더 가독성 좋고 간결하게 작성하신 거 같습니다!
잘 봤습니다.


//"Conjured" 아이템은 일반 아이템의 2배의 속도로 품질(Quality)이 저하
decreaseQuality(item, QUALITY_DECREMENT_MULTIPLIER);
decreaseSellIn(item);

// 판매 기한이 0일 이하인 경우, 품질(Quality)을 추가로 2배 감소
if (item.sellIn < QUALITY_MIN && item.quality > QUALITY_MIN) {
item.quality -= QUALITY_DECREMENT_MULTIPLIER;
}

if (item.quality < QUALITY_MIN) {
item.quality = QUALITY_MIN;
}
}
}
19 changes: 19 additions & 0 deletions Java/src/main/java/com/gildedrose/update/DefaultItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.gildedrose.update;

import static com.gildedrose.update.ItemConstants.*;

import com.gildedrose.Item;

public class DefaultItem extends UpdateLogic{

@Override
public void update(Item item) {

decreaseQuality(item, DEFAULT_QUALITY_DECREMENT);
decreaseSellIn(item);

if (item.sellIn < 0) {
decreaseQuality(item, DEFAULT_QUALITY_DECREMENT);
}
}
}
9 changes: 9 additions & 0 deletions Java/src/main/java/com/gildedrose/update/ItemConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.gildedrose.update;

public class ItemConstants {
public static final int QUALITY_MAX = 50;
public static final int QUALITY_MIN = 0;
public static final int DEFAULT_QUALITY_INCREMENT = 1;
public static final int DEFAULT_QUALITY_DECREMENT = 1;
public static final int QUALITY_DECREMENT_MULTIPLIER = 2;
}
10 changes: 10 additions & 0 deletions Java/src/main/java/com/gildedrose/update/Sulfuras.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.gildedrose.update;

import com.gildedrose.Item;

public class Sulfuras extends UpdateLogic {
@Override
public void update(Item item) {

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

import static com.gildedrose.update.ItemConstants.*;

import com.gildedrose.Item;

public abstract class UpdateLogic {

//판매일(SellIn) 감소
public void decreaseSellIn(Item item) {
item.sellIn--;
}

//품질(Quality)를 지정한 increment만큼 증가
public void increaseQuality(Item item, int increment) {
item.quality = Math.min(item.quality + increment, QUALITY_MAX); // QUALITY_MAX 이상으로 증가하지 않음
}

//품질(Quality)를 지정한 decrement만큼 감소
public void decreaseQuality(Item item, int decrement) {
item.quality = Math.max(item.quality - decrement, QUALITY_MIN); // QUALITY_MIN 이하로 감소하지 않음
}

public abstract void update(Item item);
}
20 changes: 20 additions & 0 deletions Java/src/main/java/com/gildedrose/update/UpdateLogicFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.gildedrose.update;

import com.gildedrose.Item;

public class UpdateLogicFactory {
public static UpdateLogic getUpdateLogic(Item item){
switch (item.name) {
case "Aged Brie":
return new AgedBrie();
case "Backstage passes to a TAFKAL80ETC concert":
return new BackstagePass();
case "Sulfuras, Hand of Ragnaros":
return new Sulfuras();
case "Conjured Mana Cake":
return new Conjured();
default:
return new DefaultItem();
}
}
}
Comment on lines +3 to +20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch - case로 더 명확한 구조를 가지고 있네요!
다만 나중에 제품의 종류가 많아지면 코드가 더 길어질거 같습니다~!