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차 과제 제출 #4

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 added .DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

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

6 changes: 6 additions & 0 deletions .idea/jpa-buddy.xml

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

3 changes: 3 additions & 0 deletions .idea/misc.xml

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

4 changes: 3 additions & 1 deletion .idea/networking1~2.iml

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

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

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

56 changes: 7 additions & 49 deletions Java/src/main/java/com/gildedrose/GildedRose.java
Original file line number Diff line number Diff line change
@@ -1,62 +1,20 @@
package com.gildedrose;

import com.gildedrose.Item;
import com.gildedrose.rules.LogicFactory;

class GildedRose {
Item[] items;
LogicFactory logicFactory;

public GildedRose(Item[] items) {
this.items = items;
this.logicFactory = new LogicFactory();
}

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) {
logicFactory.getLogic(item).update(item); //아이템에 맞는 로직을 찾아 quality와 sellIn 업데이트
}
}
}
4 changes: 2 additions & 2 deletions Java/src/main/java/com/gildedrose/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public Item(String name, int sellIn, int quality) {
this.quality = quality;
}

@Override
public String toString() {
@Override
public String toString() {
return this.name + ", " + this.sellIn + ", " + this.quality;
}
}
15 changes: 15 additions & 0 deletions Java/src/main/java/com/gildedrose/rules/AgedBrieLogic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.gildedrose.rules;

import com.gildedrose.Item;

public class AgedBrieLogic extends Logic {
@Override
public void update(Item item) {
decreaseSellIn(item);

increaseQuality(1, item);
if (!checkValid(item)) {
increaseQuality(1, item);
}
}
}
22 changes: 22 additions & 0 deletions Java/src/main/java/com/gildedrose/rules/BackStagePassesLogic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.gildedrose.rules;

import com.gildedrose.Item;

public class BackStagePassesLogic extends Logic {
@Override
public void update(Item item) {
if (item.sellIn <= 5) {
increaseQuality(3, item);
} else if (item.sellIn <= 10) {
increaseQuality(2, item);
} else {
increaseQuality(1, item);
}

decreaseSellIn(item);

if (!checkValid(item)) {
item.quality = 0;
}
}
}
16 changes: 16 additions & 0 deletions Java/src/main/java/com/gildedrose/rules/CommonLogic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.gildedrose.rules;

import com.gildedrose.Item;

public class CommonLogic extends Logic {
@Override
public void update(Item item) {
decreaseSellIn(item);

if (!checkValid(item)) {
decreaseQuality(2, item);
} else {
decreaseQuality(1, item);
}
}
}
16 changes: 16 additions & 0 deletions Java/src/main/java/com/gildedrose/rules/ConjuredLogic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.gildedrose.rules;

import com.gildedrose.Item;

public class ConjuredLogic extends Logic {
@Override
public void update(Item item) {
decreaseSellIn(item);

if (!checkValid(item)) {
decreaseQuality(4, item);
} else {
decreaseQuality(2, item);
}
}
}
26 changes: 26 additions & 0 deletions Java/src/main/java/com/gildedrose/rules/Logic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.gildedrose.rules;

import com.gildedrose.Item;

public abstract class Logic {
private static final int QUALITY_MAX = 50;
private static final int QUALITY_MIN = 0;

public abstract void update(Item item);

protected void decreaseSellIn(Item item) {
item.sellIn = item.sellIn - 1;
}

protected void decreaseQuality(int amount, Item item) {
item.quality = Math.max(item.quality - amount, QUALITY_MIN);
}

protected void increaseQuality(int amount, Item item) {
item.quality = Math.min(item.quality + amount, QUALITY_MAX);
}

protected boolean checkValid(Item item) { //기한이 지났는 지 검사
return item.sellIn >= 0;
}
}
27 changes: 27 additions & 0 deletions Java/src/main/java/com/gildedrose/rules/LogicFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.gildedrose.rules;

import java.util.HashMap;
import java.util.Map;

import com.gildedrose.Item;

public class LogicFactory {
public static Map<String, Logic> logics = new HashMap<String, Logic>();

public LogicFactory() {
logics.put("Common", new CommonLogic());
logics.put("Aged Brie", new AgedBrieLogic());
logics.put("Backstage passes to", new BackStagePassesLogic());
logics.put("Sulfuras, Hand of Ragnaros", new SulfurasLogic());
logics.put("Conjured", new ConjuredLogic());
}

public Logic getLogic(Item item) {
for (String key : logics.keySet()) { //logics의 키에 있는 값을 이름에서 포함하는 지 검사하여 맞는 로직 선택
if (item.name.contains(key)) {
return logics.get(key);
}
}
return logics.get("Common");
}
}
9 changes: 9 additions & 0 deletions Java/src/main/java/com/gildedrose/rules/SulfurasLogic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.gildedrose.rules;

import com.gildedrose.Item;

public class SulfurasLogic extends Logic {
@Override
public void update(Item item) {
}
}