-
Notifications
You must be signed in to change notification settings - Fork 0
LV1, LV2 #8
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?
LV1, LV2 #8
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,24 @@ | ||
| package com.example.maddaewoole; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| public class Daewoole { | ||
| public int now_anger = 0; | ||
| public int anger_threshold; | ||
| public Map<String, Integer> anger_map = new HashMap<>(); | ||
|
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. 자바는 보통 변수명을 카멜케이스로 작성합니다! |
||
|
|
||
| } | ||
| public int getAnger_threshold() { | ||
| return anger_threshold; | ||
| } | ||
| Daewoole(List<String> str){ | ||
| anger_threshold = (int) ((Math.random() * 40) + 80); | ||
|
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. 40, 80, 10000과 같이 직접 수를 작성하기보단, 변수명을 주는건 어떨까요? |
||
| anger_map.put(str.get(0), (int)(Math.random() * 10000) % 20); | ||
| anger_map.put(str.get(1), (int)(Math.random() * 20) + 10); | ||
| anger_map.put(str.get(2), (int)(Math.random() * 20) + 30); | ||
| } | ||
|
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. 생성자는 뭐하는 애고, 어떻게 써야할까? 에 대해 고민해봅시다!!! https://tecoble.techcourse.co.kr/post/2020-05-26-static-factory-method/ |
||
| int beProvinced(String str){ | ||
| return anger_map.get(str); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,17 @@ | ||
| package com.example.maddaewoole; | ||
|
|
||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Jpark2 { | ||
| private List<String> str = List.of("'당신의 지각비, 회식비로 대체되었다'", "'코딩 그렇게 하는 거 아닌데'", "'오늘 저녁은 감탄계'"); | ||
|
|
||
| String prov(){ | ||
| int random_num = (int) ((Math.random()*10000)%3); | ||
| return str.get(random_num); | ||
| } | ||
|
|
||
| public List<String> getStr() { | ||
| return str; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,21 @@ | |
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| Jpark2 jiwon = new Jpark2(); | ||
| Daewoole daewook = new Daewoole(jiwon.getStr()); | ||
|
|
||
| int attack_cnt = 0; | ||
| while (true) { | ||
| String attack = jiwon.prov(); | ||
| int daewookAnger = daewook.beProvinced(attack); | ||
| System.out.println("지원은 " + attack + "를 시전하여 대욱의 분노를 " + daewookAnger + " 증가시켰다."); | ||
| daewook.now_anger += daewookAnger; | ||
| System.out.println("현재 대욱의 분노 수치 : " + daewook.now_anger); | ||
| if (daewook.now_anger > daewook.getAnger_threshold()) { | ||
| break; | ||
| } | ||
|
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. 각자의 코딩 스타일이 있겠지만, 무한루프보다는 탈출조건까지만 함수를 시행하는건 어떨까요?? |
||
| attack_cnt++; | ||
| } | ||
| System.out.println("대욱을 도발한 횟수 : " + attack_cnt + "회"); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,88 @@ | ||
| package com.example.bot; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
|
|
||
| public class BotImpl implements JiwonBehavior { | ||
|
|
||
| private final Map<String, Integer> product = new HashMap<>(); | ||
|
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. Map 등의 Collection류 변수명은 복수형으로 작성해주시면 좋습니다! |
||
|
|
||
| @Override | ||
| public void takeOrder(String order) { | ||
| if (order.equals("얼마야?")) { | ||
| result(); | ||
| return; | ||
| } | ||
| int loc = order.indexOf('>'); | ||
| String name = order.substring(1, loc); | ||
| order = order.substring(loc + 1); | ||
|
Comment on lines
+17
to
+19
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.
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.
|
||
|
|
||
| if (order.equals("빼")) { | ||
| outProduct(name); | ||
| } else if (order.equals("시켰나?")) { | ||
| didIOrdered(name); | ||
|
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. 'I'와 같은 표현은 주로 사용하지 않습니다..!
|
||
| } else if (order.equals("몇 개야?")) { | ||
| howManyOrdered(name); | ||
|
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. 메서드명은 맨 앞에 동사가 오게끔 작성해주세요! |
||
| } else { | ||
| orderProducts(order, name); | ||
| } | ||
| } | ||
|
|
||
| private void orderProducts(String order, String name) { | ||
| int price = name.length() * 1000; | ||
|
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. '1000'과 같은 부분은 정책적으로 변경될 여지가 있는 부분인데, 해당하는 부분의 변경에 대해서 상수 값으로 관리하지 않으면 이후에 변경된 시점에 일일히 바꿔주어야 합니다..! 정책적으로 지정된 값들에 대해서는 별도의 상수(static final 혹은 enum)로 관리해주시는게 좋을 것 같습니다! |
||
| if (product.containsKey(name)) { | ||
| product.put(name, product.get(name) + 1); | ||
| } else { | ||
|
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. Map에서 get을 쓴다는 것.. NullPointException을 감내한다는 것.. input에 대한 예외사항을 견딜 자신이 있다는 것..!! |
||
| product.put(name, 1); | ||
| } | ||
|
|
||
| if (order.indexOf('랑') >= 0) { | ||
| int loc = order.indexOf('<'); | ||
| name = order.substring(loc + 1, order.length() - 1); | ||
| price += name.length() * 1000; | ||
| if (product.containsKey(name)) { | ||
| product.put(name, product.get(name) + 1); | ||
| } else { | ||
| product.put(name, 1); | ||
| } | ||
|
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. 책임 분리란 무엇일까여.. 항상 고민되는 부분입니다. |
||
|
|
||
| } | ||
| System.out.println("네 " + price + "원이요"); | ||
| } | ||
|
|
||
| private void outProduct(String name) { | ||
| if (product.containsKey(name)) { | ||
| product.remove(name); | ||
| System.out.println("네"); | ||
| } else { | ||
| System.out.println("<" + name + ">안 시키셨어요"); | ||
| } | ||
| } | ||
|
|
||
| private void didIOrdered(String name) { | ||
| if (product.containsKey(name)) { | ||
| System.out.println("<" + name + ">시키셨어요"); | ||
| } else { | ||
| System.out.println("<" + name + ">안 시키셨어요"); | ||
| } | ||
| } | ||
|
|
||
| private void howManyOrdered(String name) { | ||
| if (product.containsKey(name)) { | ||
| System.out.println("<" + name + ">" + product.get(name) + "개요"); | ||
| } else { | ||
| System.out.println("<" + name + ">안 시키셨어요"); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void result() { | ||
| int total = 0; | ||
| for (String key : product.keySet()) { | ||
| total += key.length() * 1000 * product.get(key); | ||
| } | ||
| System.out.println("총 " + total + "원 입니다"); | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,38 @@ | ||
| package com.example.algorithmbot; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| BFS bfs = new BFS(); | ||
| DFS dfs = new DFS(); | ||
| TwoPointer twoPointer = new TwoPointer(); | ||
| BinarySearch binarySearch = new BinarySearch(); | ||
| DP dp = new DP(); | ||
|
|
||
| List<Algorithm> algorithm = new ArrayList<>( | ||
| Arrays.asList(bfs, dfs, twoPointer, binarySearch, dp)); | ||
|
Comment on lines
+10
to
+17
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. List<Algorithm> algorithms = List.of(new BFS(), new DFS()...);
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. 언급해주신바와 같이 JDK 17의 좋은 업데이트 Collections 대신 List.of로 축약하는 기능을 사용하신다면 당신은 자바 멋쟁이 |
||
| List<String> todayAlgorithm = new ArrayList<>( | ||
| Arrays.asList("BFS", "DFS", "TwoPointer", "BinaraySearch", "DP")); | ||
|
Comment on lines
+18
to
+19
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.
|
||
|
|
||
| Wchae wchae = new Wchae(); | ||
|
|
||
| for (int i = 0; i < 20; i++) { | ||
| int today1 = (int) ((Math.random() * 10) % 5); | ||
| int today2 = (int) ((Math.random() * 10) % 5); | ||
|
|
||
| Algorithm todayAlgorithm1 = algorithm.get(today1); | ||
| Algorithm todayAlgorithm2 = algorithm.get(today2); | ||
|
Comment on lines
+24
to
+28
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. today1, today2 라는 변수명이 나오게 된 경위가 '풀 수 있는 알고리즘 전체의 이름을 가진 리스트'를 기준으로 '해당하는 리스트의 원소 개수가 끝 값인 난수'를 지정한 후에 '인덱스로 지정해서 두 가지를 뽑아낸다'로 이해했는데, today1, today2라는 이름은 직관적으로 다른 사람이 이해하기 어려울 수 있으므로 Algorithm todayAlgorithm1 = algorithm.get((int) ((Math.random() * 10) % 5));
Algorithm todayAlgorithm2 = algorithm.get((int) ((Math.random() * 10) % 5));라는 방식으로 표현할 수 있을 것 같습니다. Algorithm todayAlgorithm1 = algorithm.get(getRandomIntByRange(1, 5)); |
||
|
|
||
| System.out.println( | ||
| "오늘의 알고리즘 : " + todayAlgorithm.get(today1) + ", " + todayAlgorithm.get(today2)); | ||
|
Comment on lines
+30
to
+31
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. 해당 부분은 todayAlgorithm1, 2를 대입해서 사용할 수 있을 것 같은데 아마도 깜빡하신 부분인 것 같습니다! |
||
| System.out.println( | ||
| "우주 : " + wchae.solveAlgorithm(todayAlgorithm1) + " / " + wchae.solveAlgorithm( | ||
| todayAlgorithm2)); | ||
| } | ||
|
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,5 +1,30 @@ | ||
| package com.example.algorithmbot; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
|
|
||
| public class Wchae { | ||
|
|
||
| private final Map<Algorithm, Integer> algorithmMap = new HashMap<>(); | ||
|
|
||
| public String solveAlgorithm(Algorithm haveToSolve) { | ||
|
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. 매개변수 명이 haveToSolve인 것 보다는 Algorithm algorithm으로 적어주시는 것이 가독성에 더 좋을 것 같습니다! (해당 메서드로 들어온 이상 solve를 진행하는 것은 보장되어 있기 때문에) |
||
| Optional<Algorithm> today1 = algorithmMap.keySet().stream() | ||
| .filter(x -> x.isSolution(haveToSolve)).findFirst(); | ||
|
Comment on lines
+12
to
+13
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. 람다식을 사용하실 때 사용되는 변수에 대해서는 변수명을 명기해주시는 것이 좋습니다! Optional<Algorithm> today1 = algorithmMap.keySet().stream()
.filter(algorithm -> algorithm.isSolution(haveToSolve))
.findFirst();
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. 람다식 마스터 hyowchoi? |
||
|
|
||
| if (today1.isPresent()) { | ||
| int solved_cnt = algorithmMap.getOrDefault(haveToSolve, 0); | ||
|
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. 스네이크 케이스 -> 카멜 케이스 주의해주세요! |
||
| algorithmMap.put(haveToSolve, solved_cnt + 1); | ||
| double percentage = Math.random(); | ||
| if ((double) solved_cnt * 0.1 > percentage) { | ||
| return haveToSolve.getSolution(); | ||
| } else { | ||
| return "스트레스 받네..."; | ||
| } | ||
| } else { | ||
| algorithmMap.put(haveToSolve, 1); | ||
| return "스트레스 받네..."; | ||
| } | ||
| } | ||
|
|
||
| } | ||
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.
클래스 내부에 property(필드)를 갖고 있다면, 해당 필드를 갖고 뭘 할 수 있을까? 얘를 갖고 어떤 기능을 넣고, 이용할 수 있을까? 에 대한 고민을 하면 정말 조습니다.
할 수 있는게 없다면, 진짜 필요한 필드일까?에 대해 고민해보아여