-
Notifications
You must be signed in to change notification settings - Fork 0
Be/main/jongmlee java lv0 #17
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
d611f23
2967df2
4fb53c2
dce5b60
bf036df
f3bb2cf
e3a1d03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,42 @@ | ||
| package com.example.maddaewoole; | ||
|
|
||
| import static com.example.maddaewoole.Utils.MENT1; | ||
| import static com.example.maddaewoole.Utils.MENT2; | ||
| import static com.example.maddaewoole.Utils.MENT3; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| public class Daewoole { | ||
|
|
||
| private final int angerLimit; | ||
| private final Map<String, Integer> angerMap; | ||
| private int angerLevel; | ||
|
|
||
| public Daewoole() { | ||
| angerLevel = 0; | ||
| angerLimit = Utils.getRandomNumber(80, 121); | ||
| System.out.printf("이번 대욱의 분노 임계값은 %d입니다.\n\n", angerLimit); | ||
|
||
| angerMap = new HashMap<>(); | ||
| angerMap.put(MENT1, Utils.getRandomNumber(0, 21)); | ||
| angerMap.put(MENT2, Utils.getRandomNumber(10, 31)); | ||
| angerMap.put(MENT3, Utils.getRandomNumber(30, 51)); | ||
| } | ||
|
|
||
| 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() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 static com.example.maddaewoole.Utils.MENT1; | ||
| import static com.example.maddaewoole.Utils.MENT2; | ||
| import static com.example.maddaewoole.Utils.MENT3; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class Jpark2 { | ||
|
|
||
| private final List<String> provocations = new ArrayList<>(); | ||
|
|
||
| public Jpark2() { | ||
| provocations.add(MENT1); | ||
| provocations.add(MENT2); | ||
| provocations.add(MENT3); | ||
| } | ||
|
Comment on lines
+14
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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())); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 하나의 클래스는 머로 구성될까여?? |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,20 @@ | |
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| Jpark2 jpark2 = new Jpark2(); | ||
| Daewoole daewoole = new Daewoole(); | ||
| int cnt = 0; | ||
| while (true) { | ||
| String ment = jpark2.provocate(); | ||
| int anger = daewoole.provoked(ment); | ||
| System.out.printf("지원은 '%s'를 시전하여 대욱의 분노를 %d 증가시켰다.\n현재 대욱의 분노 수치 : %d\n\n", ment, | ||
|
||
| anger, | ||
| daewoole.getAngerLevel()); | ||
| cnt++; | ||
| if (daewoole.isOverAngerLimit()) { | ||
|
||
| System.out.printf("참지 못한 대욱은 결국 지원에게 잼민 펀치를 날렸다.\n대욱을 도발한 횟수 : %d회\n", cnt); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.example.maddaewoole; | ||
|
|
||
| import java.util.Random; | ||
| import java.util.concurrent.ThreadLocalRandom; | ||
|
|
||
| public class Utils { | ||
|
|
||
| static final String MENT1 = "당신의 지각비, 회식비로 대체되었다"; | ||
| static final String MENT2 = "코딩 그렇게 하는거 아닌데"; | ||
| static final String MENT3 = "오늘 저녁은 감탄계"; | ||
|
|
||
| public static int getRandomNumber(int min, int max) { | ||
| Random random = ThreadLocalRandom.current(); | ||
| return random.nextInt(min, max); | ||
| } | ||
| } | ||
lamodadite marked this conversation as resolved.
Show resolved
Hide resolved
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
매직넘버를 쓰는 습관을 들여봅시다!!
80, 121, 0, 21, 10, 31... 수가 너무 많은데 매직넘버로 다 어케바꿔요? 라는 생각이 든다면
범위 설정을 잘못했나.. 스스로 의심을 해보기!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
매직넘버를 상수로 바꾸니 가독성이 훨씬 좋아졌습니다!!