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

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

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

Daewoole() {
Copy link
Contributor

Choose a reason for hiding this comment

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

접근제어자가 멀까요? 생성자는 어떤 역할을 하는걸까여??
하나의 클래스에 함께 존재하는 변수와 메서드는 어떤 의미를 가져야 하는가.. 객체지향은 어렵다

Copy link
Author

Choose a reason for hiding this comment

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

아무 생각 없이 cpp처럼 만들었는데 자바에는. default라는게 있었군요. 새로운 접근제어자를 배울 수 있었습니다 감사합니다!!
다른 패키지에서도 생성할 수 있도록 public으로 변경했습니다.

Random random = new Random();
angryPoint = 0;
angryLimit = random.nextInt(41) + 80;
Copy link
Contributor

Choose a reason for hiding this comment

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

매직넘버를 사용해봅시다!!
41, 80과 같이 직접 변수를 넣어주기 보다는, 의미를 주면 가독성과 유지보수가 좋은 코드가 될거에여!!

Copy link
Author

Choose a reason for hiding this comment

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

넵 유지보수를 위한 코드를 고민해볼 수 있어서 좋았습니다. 수정완료했습니다 :)

prevokeCount = 0;
punchFlag = true;
prevokePoints = new HashMap<String, Integer>();

prevokePoints.put("당신의 지각비, 회식비로 대체되었다", random.nextInt(21));
Copy link
Contributor

Choose a reason for hiding this comment

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

의도는 베리 굿인데여??
방식을 조금만 바꿔봅시다! 쩨이팍의 멘트와 정확히 중복되고 있으니 쩨이팍으로부터 멘트공격을 받으면, 분노 수치가 쌓이도록 바꿔보는건 어떠실까여?

Copy link
Author

Choose a reason for hiding this comment

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

  • 각각의 랜덤 값은 클래스 생성 시에, 생성자에서 정해집니다.
    리드미에서 대욱 클래스에 대해서 이렇게 설명하고있어서 어떤 방향으로 수정해야할지 감이 잘 잡히지 않습니다.

Copy link
Author

@duckgii duckgii Jan 14, 2025

Choose a reason for hiding this comment

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

각 도발 문자열마다 가지는 도발 수치의 랜덤값이 다르기 때문에 제이팍으로부터 문자열을 받아서 그때 랜덤값을 생성하는 방식은 적용하지 않았습니다! 모두 동일한 범위의 랜덤값이라면 같은 명령어를 통해 설정할 수 있지만, 이 문제에서는 결국 하드코딩이 필요한 조건이라고 생각합니다. 멘트 부분은 static으로 선언해서 리터럴 문자열은 하나만 있도록 수정해보겠습니다!!

prevokePoints.put("코딩 그렇게 하는거 아닌데", random.nextInt(21) + 10);
prevokePoints.put("오늘 저녁은 감탄계", random.nextInt(21) + 30);
}

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.println("참지 못한 대욱은 결국 지원에게 잼민 펀치를 날렸다."); // println은 무조건 string으로만 출력
System.out.printf("대욱을 도발한 횟수 : %d회\n", prevokeCount); //출력 서식을 사용하려면 printf
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
package com.example.maddaewoole;

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

public class Jpark2 {
private final ArrayList<String> ment; // final을 붙이면 arraylist 객체의 주소를 변경할 수 없는거지 ArrayList 클래스 내부 메서드를 이용한 값 변경은 가능하다
Copy link
Contributor

Choose a reason for hiding this comment

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

보통 Collection 객체의 변수명은 복수형으로 작성! ment -> ments 권장드립니다

ArrayList로 작성한건 구현체를 의도하신건가여?! 생성자 내에서 초기화 시에도 동일하게 작성을 하셨던데,
멤버변수 선언 시 타입을 String으로 정의하셨다면, 제네릭 타입 추론이 가능하기 때문에 new ArrayList<>(); 이렇게 생략도 가능합니다!

Copy link
Author

Choose a reason for hiding this comment

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

넵 조언 덕분에 제네릭에 대해 자세히 공부해볼 수 있었습니다 감사합니다 :)
수정 완료했습니다!!


Jpark2() {
ment = new ArrayList<String>();
ment.add("당신의 지각비, 회식비로 대체되었다");
ment.add("코딩 그렇게 하는거 아닌데");
ment.add("오늘 저녁은 감탄계");
}
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(ment.size());

return (ment.get(idx));
}

public void checkPoint(int angryPoint) {
System.out.printf("현재 대욱의 분노 수치 : %d\n", 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();

while (true) {
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("지원은 '%s'를 시전하여 대욱의 분노를 %d 중가시켰다.\n", 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();
break;
}
}
}
}