Skip to content
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
package com.example.maddaewoole;

import java.util.HashMap;
import java.util.Random;

public class Daewoole {
private final static int ANGRYLIMIT_DEFAULT = 80;
private final static int ANGRYLIMIT_RANGE = 41;
private final static int PREVOKE_RANGE = 21;
private final static int PREVOKE_DEFAULT1 = 10;
private final static int PREVOKE_DEFAULT2 = 30;
private final static String PREVOKE_MENT1 = "당신의 지각비, 회식비로 대체되었다";
private final static String PREVOKE_MENT2 = "코딩 그렇게 하는거 아닌데";
private final static String PREVOKE_MENT3 = "오늘 저녁은 감탄계";
private final static String PUNCH_MENT = "참지 못한 대욱은 결국 지원에게 잼민 펀치를 날렸다.\n대욱을 도발한 횟수 : %d회\n";
Copy link

Choose a reason for hiding this comment

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

변수로 출력형식 지정해둔 것 구웃

private final HashMap<String, Integer> prevokePoints;
private final int angryLimit;
private int angryPoint;
private int prevokeCount;
private boolean punchFlag;

public Daewoole() {
Random random = new Random();
angryPoint = 0;
angryLimit = random.nextInt(ANGRYLIMIT_RANGE) + ANGRYLIMIT_DEFAULT;
prevokeCount = 0;
punchFlag = true;
prevokePoints = new HashMap<>();

prevokePoints.put(PREVOKE_MENT1, random.nextInt(PREVOKE_RANGE));
prevokePoints.put(PREVOKE_MENT2, random.nextInt(PREVOKE_RANGE) + PREVOKE_DEFAULT1);
prevokePoints.put(PREVOKE_MENT3, random.nextInt(PREVOKE_RANGE) + PREVOKE_DEFAULT2);
}

public int getAngryPoint() {
return (angryPoint);
}

public boolean getPunchFlag() {
return (punchFlag);
}

public int bePrevoked(String ment) {
angryPoint += prevokePoints.get(ment);
prevokeCount++;
if (angryPoint > angryLimit)
punchFlag = false;
return (prevokePoints.get(ment));
Copy link

Choose a reason for hiding this comment

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

Suggested change
public boolean getPunchFlag() {
return (punchFlag);
}
public int bePrevoked(String ment) {
angryPoint += prevokePoints.get(ment);
prevokeCount++;
if (angryPoint > angryLimit)
punchFlag = false;
return (prevokePoints.get(ment));
public boolean isDaewooleAngered() {
return angryPoint > angryLimit;
}
public int bePrevoked(String ment) {
angryPoint += prevokePoints.get(ment);
prevokeCount++;
return prevokePoints.get(ment);

punchFlag 대신 (angryPoint > angryLimit)로 임계점을 판단하는 게 더 좋을 것 같습니다

}

public void punch() {
System.out.printf(PUNCH_MENT, prevokeCount); //출력 서식을 사용하려면 printf
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
package com.example.maddaewoole;

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

public class Jpark2 {
private final static String PREVOKE_MENT1 = "당신의 지각비, 회식비로 대체되었다";
private final static String PREVOKE_MENT2 = "코딩 그렇게 하는거 아닌데";
private final static String PREVOKE_MENT3 = "오늘 저녁은 감탄계";
private final static String POINTCHECK_MENT = "현재 대욱의 분노 수치 : %d\n";
private final ArrayList<String> ments;

public Jpark2() {
ments = new ArrayList<>(List.of(PREVOKE_MENT1, PREVOKE_MENT2, PREVOKE_MENT3));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

구현체로 선언 하고, 생성자에서 초기화 후 값을 채워넣는 방식이군용
그렇다면 List<String> ments = new ArrayList<>(List.of("멘트1", "멘트2", "멘트3"));
이렇게 하면 동일한 의미가 될 것 같습니다! List.of()는 불변 리스트를 반환하고, newArrayList<> 안에 넣어서 가변 리스트로 변환하면 좋을 것 같읍니다

Copy link
Author

Choose a reason for hiding this comment

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

ArrayList의 생성자 괄호 속에는 초기 용량 또는 Collection만 가능하다는 것을 알 수 있었습니다. 감사합니다 :)
수정 완료했습니다!!


public String prevoke() {
Copy link

Choose a reason for hiding this comment

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

Suggested change
public String prevoke() {
public String provoke() {

오타 이슈

Random random = new Random();
int idx = random.nextInt(ments.size());

return (ments.get(idx));
}

public void checkPoint(int angryPoint) {
System.out.printf(POINTCHECK_MENT, angryPoint);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
public class Main {

public static void main(String[] args) {
Jpark2 jpark2 = new Jpark2();
Daewoole daewoole = new Daewoole();
final String PRINT_MENT = "지원은 '%s'를 시전하여 대욱의 분노를 %d 중가시켰다.\n";

while (daewoole.getPunchFlag()) {
String ment;
int prevokePoint;

ment = jpark2.prevoke();
prevokePoint = daewoole.bePrevoked(ment);
Copy link

Choose a reason for hiding this comment

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

Suggested change
String ment;
int prevokePoint;
ment = jpark2.prevoke();
prevokePoint = daewoole.bePrevoked(ment);
String ment = jpark2.prevoke();
int prevokePoint = daewoole.bePrevoked(ment);

선언과 동시에 할당을 하는 것이 권장돼요

System.out.printf(PRINT_MENT, ment, prevokePoint);
jpark2.checkPoint(daewoole.getAngryPoint());
System.out.println();
if (!daewoole.getPunchFlag()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

어디까지나 취향 차이지만, 무한루프보다는 탈줄조건을 while 안에 넣어주는건 어떠신가여?

Copy link
Author

Choose a reason for hiding this comment

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

네 가독성 측면에서 그게 더 좋을 것 같습니다!! 수정 완료했습니다.

daewoole.punch();
}
Copy link

Choose a reason for hiding this comment

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

이 부분 수정하고 안 뺀 거겠죠..?

}
}
}