-
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 all 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,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() { | ||
| 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
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 |
|---|---|---|
| @@ -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
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.
Suggested change
하우 어바웃 디스 |
||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| public static void printDaewoolePunchedJpark2(int provokedCnt) { | ||||||||||||||||||||
| System.out.printf("참지 못한 대욱은 결국 지원에게 잼민 펀치를 날렸다.\n대욱을 도발한 횟수 : %d회\n", provokedCnt); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
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.
angerLimit이라는 멤버 변수를 대욱이 갖고 있으니, 멤버 변수에 대한 임계점 판별 메서드를 스스로 판단하도록 하는 책임 분리 좋아여~!