diff --git "a/v1/backend/JAVA_LV_0_\354\236\274\353\257\274_\355\216\200\354\271\230/docs/README.md" "b/v1/backend/JAVA_LV_0_\354\236\274\353\257\274_\355\216\200\354\271\230/docs/README.md" new file mode 100644 index 0000000..5ed7b1e --- /dev/null +++ "b/v1/backend/JAVA_LV_0_\354\236\274\353\257\274_\355\216\200\354\271\230/docs/README.md" @@ -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을 넘었는지 판별하는 기능 + diff --git "a/v1/backend/JAVA_LV_0_\354\236\274\353\257\274_\355\216\200\354\271\230/src/main/java/com/example/maddaewoole/Daewoole.java" "b/v1/backend/JAVA_LV_0_\354\236\274\353\257\274_\355\216\200\354\271\230/src/main/java/com/example/maddaewoole/Daewoole.java" index 40d4298..348697d 100644 --- "a/v1/backend/JAVA_LV_0_\354\236\274\353\257\274_\355\216\200\354\271\230/src/main/java/com/example/maddaewoole/Daewoole.java" +++ "b/v1/backend/JAVA_LV_0_\354\236\274\353\257\274_\355\216\200\354\271\230/src/main/java/com/example/maddaewoole/Daewoole.java" @@ -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 provokeMap = new HashMap<>(); + + public Daewoole(List 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 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; + } } diff --git "a/v1/backend/JAVA_LV_0_\354\236\274\353\257\274_\355\216\200\354\271\230/src/main/java/com/example/maddaewoole/Jpark2.java" "b/v1/backend/JAVA_LV_0_\354\236\274\353\257\274_\355\216\200\354\271\230/src/main/java/com/example/maddaewoole/Jpark2.java" index a786814..544e47b 100644 --- "a/v1/backend/JAVA_LV_0_\354\236\274\353\257\274_\355\216\200\354\271\230/src/main/java/com/example/maddaewoole/Jpark2.java" +++ "b/v1/backend/JAVA_LV_0_\354\236\274\353\257\274_\355\216\200\354\271\230/src/main/java/com/example/maddaewoole/Jpark2.java" @@ -1,5 +1,25 @@ package com.example.maddaewoole; +import java.util.List; +import java.util.Random; + public class Jpark2 { + private final List 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 getMentions() { + return mentions; + } } diff --git "a/v1/backend/JAVA_LV_0_\354\236\274\353\257\274_\355\216\200\354\271\230/src/main/java/com/example/maddaewoole/Main.java" "b/v1/backend/JAVA_LV_0_\354\236\274\353\257\274_\355\216\200\354\271\230/src/main/java/com/example/maddaewoole/Main.java" index b8d6ddd..c27bf84 100644 --- "a/v1/backend/JAVA_LV_0_\354\236\274\353\257\274_\355\216\200\354\271\230/src/main/java/com/example/maddaewoole/Main.java" +++ "b/v1/backend/JAVA_LV_0_\354\236\274\353\257\274_\355\216\200\354\271\230/src/main/java/com/example/maddaewoole/Main.java" @@ -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()); - } + 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 + "회"); + } }