Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,50 @@
package com.example.maddaewoole;

import static com.example.maddaewoole.Jpark2.MENT1;
import static com.example.maddaewoole.Jpark2.MENT2;
import static com.example.maddaewoole.Jpark2.MENT3;

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

public class Daewoole {

private static final int ANGER_LIMIT_MIN = 80;
private static final int ANGER_LIMIT_MAX = 121;
private static final int MENT1_ANGER_MIN = 0;
private static final int MENT1_ANGER_MAX = 21;
private static final int MENT2_ANGER_MIN = 10;
private static final int MENT2_ANGER_MAX = 31;
private static final int MENT3_ANGER_MIN = 30;
private static final int MENT3_ANGER_MAX = 51;

private final int angerLimit;
private final Map<String, Integer> angerMap;
private int angerLevel;

public Daewoole() {
angerLevel = 0;
angerLimit = Utils.getRandomNumber(ANGER_LIMIT_MIN, ANGER_LIMIT_MAX);
angerMap = new HashMap<>();
angerMap.put(MENT1, Utils.getRandomNumber(MENT1_ANGER_MIN, MENT1_ANGER_MAX));
angerMap.put(MENT2, Utils.getRandomNumber(MENT2_ANGER_MIN, MENT2_ANGER_MAX));
angerMap.put(MENT3, Utils.getRandomNumber(MENT3_ANGER_MIN, MENT3_ANGER_MAX));
}

public int provoked(String ment) {
if (ment.equals(MENT1) || ment.equals(MENT2) || ment.equals(MENT3)) {
angerLevel += angerMap.get(ment);
return angerMap.get(ment);
}
System.out.println(ment + " 이라는 도발 멘트는 없습니다");
return 0;
}

public boolean isOverAngerLimit() {
Copy link
Contributor

Choose a reason for hiding this comment

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

angerLimit이라는 멤버 변수를 대욱이 갖고 있으니, 멤버 변수에 대한 임계점 판별 메서드를 스스로 판단하도록 하는 책임 분리 좋아여~!

return this.angerLevel >= this.angerLimit;
}

public int getAngerLevel() {
return this.angerLevel;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
package com.example.maddaewoole;

import java.util.ArrayList;
import java.util.List;

public class Jpark2 {

static final String MENT1 = "당신의 지각비, 회식비로 대체되었다";
static final String MENT2 = "코딩 그렇게 하는거 아닌데";
static final String MENT3 = "오늘 저녁은 감탄계";

private final List<String> provocations = new ArrayList<>();

public Jpark2() {
provocations.add(MENT1);
provocations.add(MENT2);
provocations.add(MENT3);
}
Comment on lines +14 to +18
Copy link

Choose a reason for hiding this comment

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

MENT가 바뀌지 않는다면, 생성자가 아닌 provocations에 List.of()로 직접 값을 불변 객체로 넣어도 될 것 같아요


public String provocate() {
return provocations.get(Utils.getRandomNumber(0, provocations.size()));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

하나의 클래스는 머로 구성될까여??
간단히 생각하면 변수 + 메서드라고 생각하는데, 쪠이팍 클래스가 좀 쓸쓸해보여요
쪠이팍 클래스는 어디까지 책임져야 하는것인가..

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
package com.example.maddaewoole;

import static com.example.maddaewoole.Utils.printDaewoolePunchedJpark2;
import static com.example.maddaewoole.Utils.printJpark2ProvokeDaewoole;

public class Main {

public static void main(String[] args) {

Jpark2 jpark2 = new Jpark2();
Daewoole daewoole = new Daewoole();
int cnt = 0;
while (!daewoole.isOverAngerLimit()) {
String ment = jpark2.provocate();
int anger = daewoole.provoked(ment);
printJpark2ProvokeDaewoole(ment, anger, daewoole.getAngerLevel());
cnt++;
}
printDaewoolePunchedJpark2(cnt);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.maddaewoole;

import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

public class Utils {

public static int getRandomNumber(int min, int max) {
Random random = ThreadLocalRandom.current();
return random.nextInt(min, max);
}

public static void printJpark2ProvokeDaewoole(String ment, int anger, int daewooleAngerLevel) {
System.out.printf("지원은 '%s'를 시전하여 대욱의 분노를 %d 증가시켰다.\n현재 대욱의 분노 수치 : %d\n\n", ment,
anger,
daewooleAngerLevel);
Comment on lines +14 to +16
Copy link

Choose a reason for hiding this comment

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

Suggested change
System.out.printf("지원은 '%s'를 시전하여 대욱의 분노를 %d 증가시켰다.\n현재 대욱의 분노 수치 : %d\n\n", ment,
anger,
daewooleAngerLevel);
System.out.printf(
"지원은 '%s'를 시전하여 대욱의 분노를 %d 증가시켰다.\n현재 대욱의 분노 수치 : %d\n\n",
ment,
anger,
daewooleAngerLevel
);

하우 어바웃 디스

}

public static void printDaewoolePunchedJpark2(int provokedCnt) {
System.out.printf("참지 못한 대욱은 결국 지원에게 잼민 펀치를 날렸다.\n대욱을 도발한 횟수 : %d회\n", provokedCnt);
}
}