[BE] ์ด๋ํ ๐ฅ ์ค๋์ ์ง๊ฟ์?#21
[BE] ์ด๋ํ ๐ฅ ์ค๋์ ์ง๊ฟ์?#21move-hoon wants to merge 45 commits intoLeets-Official:mainfrom
Conversation
- ์ ํจํ์ง ์์ ์ ๋ ฅ์ ๋ํ ์์ธ ๋ฉ์์ง - IllegalArgumentException ๊ฐ์ฒด๋ฅผ ์ ๊ณต
- controller์์ ์ฌ์ฉํ๊ธฐ ์ํ static ์ถ๊ฐ
- ArrayList์ ์ ๋ค๋ฆญ ํ์ ์ Member ํด๋์ค๋ก ๋ณํํ ๊ฒ์ ๋ํ ์์
- ํ๋ ์์ด ๊ทธ๋ฃนํ ํ๋ ์์ ๋ง ์ํํ๊ธฐ์ ์๋น์ค ๋ ์ด์ด๋ก ์ฎ๊ธฐ๋ ๊ฒ์ด ๋ ๋ซ๋ค๊ณ ํ๋จํ์ต๋๋ค.
- group ๋ฆฌ์คํธ๋ฅผ ๋น์ฐ๋ฉด groups ๋ฆฌ์คํธ ๋ด์ ์ถ๊ฐ๋ ํด๋น ๋ฆฌ์คํธ์ ๋ด์ฉ๋ ํจ๊ป ์ญ์ ๋๊ธฐ์ ์๋ก์ด ArrayList ์ธ์คํด์ค ํ ๋น
- ๊ธฐ์กด์ memberCount๋ฅผ ๋ฆฌํดํด์ ๋ฆฌ์คํธ ํฌ๊ธฐ๊ฐ ๊ณ ์ ๋๋ ํ์์ ํด๊ฒฐ
- groups.add(new ArrayList<>(group)) ๋ถ๋ถ์ด ์ค์ํ๋ค.
- ๊ฐ์ฒด๋ฅผ ๊ฒฐํฉํ ์๋ ์๊ธฐ์ String์ผ๋ก ํ์ ์ ๋ณํํด์ผ ํ๋ค.
| String getMessage(); | ||
|
|
||
| T getException(); | ||
| } No newline at end of file |
|
|
||
| **retry ์ ๋ ฅ** | ||
| - [x] y์ n ์ด์ธ์ ์ซ์๋ฉด ์์ธ์ฒ๋ฆฌ | ||
|
|
There was a problem hiding this comment.
์ฒดํฌ๋ฆฌ์คํธ๋ฅผ ํตํด TODO๋ฅผ ๊ด๋ฆฌํ๋ ํธ์ด ์ ๋ง ์ข์ ๊ฒ ๊ฐ์์!
|
|
||
| List<Member> membersOfList = Member.parseMembers(members); | ||
|
|
||
| boolean retry = true; |
There was a problem hiding this comment.
์ฒ์ ํ ๋๋ retry๋ผ๊ณ ํ๋๋ฐ ์๋ฏธ๊ฐ ์ ์๋ง๋๊ฑฐ ๊ฐ์ต๋๋ค. isDone๊ฐ์๊ฑด ์ด๋จ๊น์? ๊ทธ๋ฌ๋ฉด while(!isDone) ์ด๋ ๊ฒ ํด์ผํ๋๋ฐ ์์ฐ ๋๋๋ ์กฐ๊ฑด์ผ๋ก !๋ค์ด๊ฐ๋๊ฒ ์ซ๋ค๊ณ ํ๋ค์. ๊ทธ๋ผ isContinue ๋ก ํ๋ฉด ๋๋ค๊ณ ํด์! booleanํ์ ์ด๋๊น ๋ณ์๋ช ์์ is๊ฐ ๋ถ์ผ๋ฉด ๋ ์ฝ๊ธฐ ์ฌ์ธ๊ฑฐ ๊ฐ์์
| OutputView.printCompletionMessage(); | ||
|
|
||
| OutputView.printCanYouRetry(); | ||
| retry = InputView.readRetry(); |
There was a problem hiding this comment.
readRetryOpinion ์ ์ด๋จ๊น์? ์ฌ์๋์ ๋ ฅ ์ด๋ผ๋ ๋ป์ด ํจ์์ ๊ธฐ๋ฅ์ ์ ์ค๋ช ์ํด์ฃผ๋๊ฑฐ ๊ฐ์์
| import java.util.List; | ||
|
|
||
| public class GroupService { | ||
| public List<List<Member>> generateRandomGroups(List<Member> memberList, int maximumGroupSize) { |
There was a problem hiding this comment.
GPT๊ฐ ๊ฐ์ ํ ์ฝ๋์ ๋๋ค. ์ฐธ๊ณ ํ์๋ฉด ์ข์๊ฑฐ ๊ฐ์ต๋๋ค!
Collections.shuffle(memberList);
List<List<Member>> groups = new ArrayList<>();
int totalMembers = memberList.size();
int groupCount = (int) Math.ceil((double) totalMembers / maximumGroupSize);
for (int i = 0; i < groupCount; i++) {
int fromIndex = i * maximumGroupSize;
int toIndex = Math.min((i + 1) * maximumGroupSize, totalMembers);
List<Member> subList = memberList.subList(fromIndex, toIndex);
groups.add(new ArrayList<>(subList));
}
return groups;
| try { | ||
| String input = kb.nextLine(); | ||
| String[] members = input.split(","); | ||
| for (String member : members) { |
There was a problem hiding this comment.
๋ฌธ์์ด ๋ถ๋ฆฌํ๊ธฐ ์ ์ ๊ฒ์ฌํ๋ฉด ๋ฐ๋ณต ํ์์์ด ํ๋ฒ๋ง ํ ์ ์์๊ฑฐ ๊ฐ์ต๋๋ค
| } | ||
| } | ||
|
|
||
| public static int readMaxGroup(String[] members) { |
There was a problem hiding this comment.
์ฝ๋๋ค๋ ํจ์์ธ๋ฐ, ์์์ ์ถ๋ ฅ๋ ํ๋ค์! ๋ถ๋ฆฌ ํ ์๋ ์์์๊น์?
ay-eonii
left a comment
There was a problem hiding this comment.
1์ฃผ์ฐจ ๋ฏธ์
๊ณ ์ํ์
จ์ต๋๋ค๐
MVC ํจํด์ด ์ธ์๊น๋ค์ ๐๐
| import java.util.List; | ||
|
|
||
| public class MatchingController { | ||
| GroupService groupService = new GroupService(); |
There was a problem hiding this comment.
default๋ก ๋ ์ด์ ๊ฐ ์์๊น์?
| import java.util.Scanner; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class InputView { |
There was a problem hiding this comment.
๋ชจ๋ ๋ฉ์๋๊ฐ static์ด๋ค์. ๊ทธ๋ผ InputView๋ ๊ฐ์ฒด์ค๋ฝ๊ฒ ์ผํ๊ณ ์๋์?
| } | ||
|
|
||
| public static String[] readMember() { | ||
| OutputView.printStartMessage(); |
There was a problem hiding this comment.
OutputView.printStartMessage()๊ฐ ๋ฉค๋ฒ๋ฅผ ์ฝ๋ ๊ณผ์ ์ธ๊ฐ์?
์ถ๊ฐ์ ์ผ๋ก InputView๊ฐ OutputView๋ฅผ ์๋๊ฒ์ ๋ํด ์ด๋ป๊ฒ ์๊ฐํ์ธ์?
| MatchingController controller = new MatchingController(); | ||
| controller.run(); | ||
| } | ||
| } No newline at end of file |
| OutputView.printCanYouRetry(); | ||
| retry = InputView.readRetry(); | ||
|
|
||
| if (retry == true) { |
There was a problem hiding this comment.
| if (retry == true) { | |
| if (retry) { |
๋น๊ตํ ์ด์ ๊ฐ ์๋์?
| return members; | ||
| } | ||
|
|
||
| public static int memberNumber(List<Member> members) { |
There was a problem hiding this comment.
static ์ธ ์ด์ ๊ฐ ๊ถ๊ธํ๋ค์
| if (c == 'y') { | ||
| return true; | ||
| } else if (c == 'n') { | ||
| return false; |
There was a problem hiding this comment.
yellow๋ฅผ ์ ๋ ฅํด๋ ์ฌ๋งค์นญํด์ค ๊ฒ ๊ฐ์์
| int maximumGroupSize = kb.nextInt(); | ||
| kb.nextLine(); | ||
|
|
||
| checkDataValidity(memberCount, maximumGroupSize); |
There was a problem hiding this comment.
์ต๋ ์ง ์๋ ๋ฉค๋ฒ์๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์์ผํ๋ค
View๊ฐ ์ต๋ ์ง ์์ ๋ํ ์กฐ๊ฑด๊ณผ ๋ฉค๋ฒ ์๋ฅผ ์๊ณ ์๋ ๊ฑฐ ๊ฐ์์. InputView๋ ๊ฒ์ฆ์ ํ๋ ๊ฐ์ฒด์ธ๊ฐ์?

ํจํค์ง ๊ตฌ์กฐ
๋ฏธ์ ์คํ ๊ฒฐ๊ณผ
์คํ ๊ฒฐ๊ณผ
์์ธ ์ฒ๋ฆฌ
๋ฉค๋ฒ ์ด๋ฆ์ ์์ด๊ฐ ๋ค์ด๊ฐ๋ ๊ฒฝ์ฐ
์ต๋ ์ง ์๊ฐ ์ซ์๊ฐ ์๋ ๊ฒฝ์ฐ
์ต๋ ์ง ์๋ ์ด๋ฆ์ ๊ฐฏ์๋ณด๋ค ํฐ ๊ฒฝ์ฐ
์ฌ์์ ์ ๋ ฅ์ด y,n์ด ์๋๊ฒฝ์ฐ
๊ธฐ๋ฅ ๋ช ์ธ์
๐ฅ ๋ฏธ์ - ์ค๋์ ์ง๊ฟ์?
โ ํต์ฌ ๊ธฐ๋ฅ
๋ชฉํ
๋์ ์ง๊ฟ์ ์ ํด์ค ๋๋ค ์ง๊ฟ ๋งค์นญ ํ๋ก๊ทธ๋จ์ ์์ฑ
โ 1์ฃผ์ฐจ ๋ฏธ์ ๋ชฉํ
๊ณผ์ ๋ฅผ ํตํด ์๊ฐํด๋ณด๊ธฐ
โ ๊ตฌํํ ๊ธฐ๋ฅ ๋ชฉ๋ก
[ Domain ]
Member
์ฐธ๊ฐ์์ ๋ฐ์ดํฐ ๊ตฌ์กฐ์ ๊ด๋ จ ๋ก์ง์ ๋ด๋น
๋ฌธ์์ด๋ก๋ ๋ฉค๋ฒ๋ค์ ๋ฆฌ์คํธ๋ก ๋ถ๋ฆฌํ๊ณ , ์ด ๋ฉค๋ฒ์๋ฅผ ๋ฐํํฉ๋๋ค.
[ Service ]
[ View ]
InputView
๋ฉค๋ฒ ์ด๋ฆ์ ์ ๋ ฅ๋ฐ์ (,๋ก ๊ตฌ๋ถ)
์ต๋ ์ง ์๋ฅผ ์ ๋ ฅ๋ฐ์
๋ค์ ๊ตฌ์ฑํ ์ง ๋ง์ง ์ ๋ ฅ๋ฐ์(y,n)
OutputView
์ง ์ถ์ฒ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ฌ์ค(default, y)
์ธ์ฌ ๋ฉ์ธ์ง๋ฅผ ๋ณด์ฌ์ค(n)
[ Controller ]
์ง๊ถ ์ถ์ฒ ์์ฒญ์ ์ฒ๋ฆฌํ๋ ๋ก์ง์ ๊ตฌํ
โ ์์ธ ์ฒ๋ฆฌ - exception
๊ณตํต
์ด๋ฆ ์ ๋ ฅ
์ต๋ ์ง์ ์ ๋ ฅ
retry ์ ๋ ฅ