-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sohyupar java lv0 #3
Open
saewoo1
wants to merge
11
commits into
sohyupar
Choose a base branch
from
sohyupar_Java_lv0
base: sohyupar
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9c15d05
DOCS: 기능 구현 목록 작성
saewoo1 80800cd
FEAT: 랜덤한 도발 문자열을반환하는 기능
saewoo1 36761c1
FEAT: 현재 분노 수치가 한계를 넘었는지 검수하는 기능
saewoo1 f24d1ef
REFACTOR: 도발멘트 길이에 대한 랜덤 수 반환 메서드명 변경
saewoo1 fa6c3e0
FEAT: 도발 멘트에 따른 분노 수치 학습 기능
saewoo1 471b096
FEAT: 입력받은 멘트에 따른 분노 축적 기능
saewoo1 191f917
DOCS: 기능 구현 목록 업데이트
saewoo1 c64a0cf
FEAT: 출력 기능 추가
saewoo1 062bd4f
FIX: 반복 시행이 되지 않는 에러 수정
saewoo1 64471fd
STYLE: 불필요한 주석 삭제
saewoo1 61b0e78
REFACTOR: provokeMap final 접근제어자 추가
saewoo1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# 기능 구현 목록 | ||
|
||
## Jpark2 | ||
|
||
- [x] 3개의 문자열 프로퍼티 | ||
- [x] `당신의~` | ||
- [x] `코딩~` | ||
- [x] `오늘 저녁은~` | ||
|
||
- [x] 도발 문자열 중 랜덤하게 하나를 반환하는 기능 | ||
- [x] 랜덤한 값을 생성하는 기능 | ||
- [x] 인덱스에 따라 property를 반환하는 기능 | ||
|
||
## Daewoole | ||
|
||
- [ ] 프로퍼티 | ||
- 현재 분노 수치 | ||
- [x] 초기값 0 | ||
- 분노 임계값 | ||
- [x] 80 ~ 120 사이의 랜덤 값 | ||
- 도발 분노 맵 | ||
- [x] 도발에 대응되는 문자열마다 분노 수치 저장 | ||
- [x] 당신의 ~ -> 0 ~ 20 | ||
- [x] 코딩 ~ -> 10 ~ 30 | ||
- [x] 오늘 저녁은~ -> 30 ~ 50 | ||
|
||
- [x] 지정된 범위 내의 랜덤한 값을 생성하는 기능 | ||
- [x] 랜덤 값은 클래스 생성 시, 생성자에서 정해진다 | ||
- [x] 도발당하기 기능 | ||
- [x] 도발 문자별로 학습했던 분노를 축적하는 기능 | ||
- [x] 현재 지수가 limit을 넘었는지 판별하는 기능 | ||
|
60 changes: 60 additions & 0 deletions
60
v1/backend/JAVA_LV_0_잼민_펀치/src/main/java/com/example/maddaewoole/Daewoole.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,65 @@ | ||
package com.example.maddaewoole; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Random; | ||
|
||
public class Daewoole { | ||
private static final int MIN_LIMIT = 80; | ||
private static final int MAX_LIMIT = 120; | ||
private static final int ADD_MAX_POINT = 20; | ||
private static final int ADD_LAST_POINT = 10; | ||
private int anger; | ||
private final int limit; | ||
private final Map<String, Integer> provokeMap = new HashMap<>(); | ||
|
||
public Daewoole(List<String> mentions) { | ||
anger = 0; | ||
limit = generateRandomNumberInRange(MIN_LIMIT, MAX_LIMIT); | ||
learnMentions(mentions); | ||
} | ||
|
||
public void provoked(String mention) { | ||
int angerPoint = getLearnedAngerPoint(mention); | ||
|
||
addAngerPoint(angerPoint); | ||
} | ||
|
||
public int getLearnedAngerPoint(String mention) { | ||
return provokeMap.getOrDefault(mention, 0); | ||
} | ||
|
||
|
||
private void learnMentions(List<String> mentions) { | ||
int startPoint = 0; | ||
for (int i = 0; i < mentions.size(); i++) { | ||
String mention = mentions.get(i); | ||
|
||
provokeMap.put(mention, generateRandomNumberInRange(startPoint, startPoint + ADD_MAX_POINT)); | ||
if (i == mentions.size() - 1) { | ||
startPoint += ADD_MAX_POINT; | ||
} | ||
startPoint += ADD_LAST_POINT; | ||
} | ||
} | ||
|
||
// 범위 내의 랜덤값 생성 | ||
private int generateRandomNumberInRange(int min, int max) { | ||
Random random = new Random(); | ||
|
||
return random.nextInt((max - min) + 1) + min; | ||
} | ||
|
||
public boolean isOverLimit() { | ||
return anger >= limit; | ||
} | ||
|
||
private void addAngerPoint(int point) { | ||
anger += point; | ||
} | ||
|
||
public int getAnger() { | ||
return anger; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
v1/backend/JAVA_LV_0_잼민_펀치/src/main/java/com/example/maddaewoole/Jpark2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,25 @@ | ||
package com.example.maddaewoole; | ||
|
||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class Jpark2 { | ||
private final List<String> mentions = List.of("당신의 지각비, 회식비로 대체되었다", "코딩 그렇게 하는거 아닌데", "오늘 저녁은 감탄계"); | ||
|
||
public String provoke() { | ||
int randomIdx = generateRandomNumberByMentionCount(); | ||
|
||
return mentions.get(randomIdx); | ||
} | ||
|
||
private int generateRandomNumberByMentionCount() { | ||
int range = mentions.size(); | ||
|
||
Random random = new Random(); | ||
return random.nextInt(range); | ||
} | ||
|
||
public List<String> getMentions() { | ||
return mentions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,34 @@ | |
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
public static void main(String[] args) { | ||
Jpark2 jpark2 = new Jpark2(); | ||
Daewoole daewoole = new Daewoole(jpark2.getMentions()); | ||
Comment on lines
+6
to
+7
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. jpark2 객체에서 getMentions로 주입해주는 부분 좋은 것 같습니다! 다만 private final List mentions가 아닌 private final static으로 지정해서 클래스 자체에서 불러오도록 하면 더 좋았을 것 같아요! |
||
|
||
} | ||
int count = 0; | ||
while (!daewoole.isOverLimit()) { | ||
String provokeMention = jpark2.provoke(); | ||
int learnedAngerPoint = daewoole.getLearnedAngerPoint(provokeMention); | ||
|
||
printProvokeMention(provokeMention, learnedAngerPoint); | ||
daewoole.provoked(provokeMention); | ||
printAngerPoint(daewoole.getAnger()); | ||
count++; | ||
} | ||
printPunchCount(count); | ||
} | ||
|
||
private static void printProvokeMention(String mention, int angerPoint) { | ||
System.out.println("지원은 '" + mention + "'를 시전하여 대욱의 분노를 " + angerPoint + " 증가시켰다."); | ||
} | ||
|
||
private static void printAngerPoint(int angerPoint) { | ||
System.out.println("현재 대욱의 분노 수치: " + angerPoint); | ||
System.out.print(System.lineSeparator()); | ||
} | ||
|
||
private static void printPunchCount(int count) { | ||
System.out.println("참지 못한 대욱은 결국 지원에게 잼민 펀치를 날렸다."); | ||
System.out.println("대욱을 도발한 횟수 : " + count + "회"); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Random과 ThreadLocalRandom 에 대해서도 확인해보시면 좋을 것 같습니다
https://velog.io/@sojukang/Random-%EB%8C%80%EC%8B%A0-ThreadLocalRandom%EC%9D%84-%EC%8D%A8%EC%95%BC-%ED%95%98%EB%8A%94-%EC%9D%B4%EC%9C%A0
구조적으로는 더 말씀드릴게 없네요 너무 굳