-
Notifications
You must be signed in to change notification settings - Fork 14
[BE] ์ด๊ทผํ ๐ฅ ์ค๋์ ์ง๊ฟ์? #15
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
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 |
|---|---|---|
|
|
@@ -6,33 +6,105 @@ public class LeetsMateApplication { | |
|
|
||
| // ๋์ ํจ์์ ๋๋ค. | ||
| public void run() { | ||
| System.out.println("๋ฉค๋ฒ์ ์ด๋ฆ์ ์ ๋ ฅํด ์ฃผ์ธ์. (, ๋ก ๊ตฌ๋ถ)"); | ||
| Scanner sc = new Scanner(System.in); | ||
| String memberInput = sc.nextLine(); | ||
| checkHasNoEnglish(memberInput); | ||
| List<String> memberList = parseMembers(memberInput); | ||
| System.out.println("์ต๋ ์ง ์๋ฅผ ์ ๋ ฅํด ์ฃผ์ธ์."); | ||
| int maxNum = Integer.parseInt(sc.nextLine()); | ||
| checkDataValidity(memberList.size(), maxNum); | ||
| Boolean isDone = true; | ||
| while (isDone .equals(true)) { | ||
| printResult(generateRandomGroups(memberList,maxNum)); | ||
| isDone = isContinue(); | ||
| } | ||
| } | ||
|
|
||
| // ๋ฌธ์์ด๋ก๋ ๋ฉค๋ฒ๋ค์ ๋ฆฌ์คํธ๋ก ๋ถ๋ฆฌํ๋ ํจ์์ ๋๋ค. | ||
| public List<String> parseMembers(String members) { | ||
| return new ArrayList<>(); | ||
| return Arrays.asList(members.split(",")); | ||
| } | ||
|
|
||
| // ์ด ๋ฉค๋ฒ์๋ฅผ ๋ฐํํฉ๋๋ค. | ||
| public int memberNumber(List<String> members) { | ||
| return 0; | ||
| return members.size(); | ||
| } | ||
|
|
||
| // ๋ฉค๋ฒ ๋ฌธ์์ด์ ์์ด๊ฐ ์๋์ง ๊ฒ์ฌํฉ๋๋ค. ์์ด๊ฐ ์๋ค๋ฉด ์์ธ ์ถ๋ ฅ | ||
| public void checkHasNoEnglish(String members) { | ||
| try { | ||
| for (char c : members.toCharArray()) { | ||
| if (!(c >= '๊ฐ' && c <= 'ํฃ') && !(Character.toString(c).equals(","))) { | ||
|
Member
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. ๋ณต์กํ ์กฐ๊ฑด๋ฌธ์ ๋ฉ์๋๋ก ๋ฐ๋ก ๋นผ๋ฉด ๊ฐ๋ ์ฑ์ด ์ฃ ์์ ธ์ ๐ |
||
| throw new Exception("[ERROR] ์ด๋ฆ์ ํ๊ธ๋ก ์ ๋ ฅํด์ผ ํฉ๋๋ค"); | ||
| } | ||
| } | ||
| } catch (Exception e) { | ||
| System.out.println(e.getMessage()); | ||
| run(); | ||
| } | ||
| } | ||
|
|
||
| // ๋ฉค๋ฒ์์ ์ต๋ ์ง์ ๋ฐ์ดํฐ๊ฐ ์ ํจํ์ง ๊ฒ์ฌํ๋ ํจ์์ ๋๋ค. ์ ํจํ์ง ์๋ค๋ฉด ์์ธ ์ถ๋ ฅ | ||
| public void checkDataValidity(int memberCount, int maximumGroupSize) { | ||
| try { | ||
| if (memberCount < maximumGroupSize) { | ||
| throw new Exception("[ERROR] ์ต๋ ์ง ์๋ ์ด๋ฆ์ ๊ฐฏ์๋ณด๋ค ํด ์ ์์ต๋๋ค"); | ||
| } | ||
| } catch (Exception e) { | ||
| System.out.println(e.getMessage()); | ||
| run(); | ||
|
Member
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 List<List<String>> generateRandomGroups(List<String> memberList, int maximumGroupSize) { | ||
| return new ArrayList<>(); | ||
| Collections.shuffle(memberList); | ||
| List<List<String>> newMemberList = new ArrayList<>(); | ||
| List<String> newList = new ArrayList<>(); | ||
| for (String s : memberList) { | ||
| newList.add(s); | ||
| if (newList.size() == maximumGroupSize || memberList.indexOf(s) == memberList.size()-1) { | ||
| newMemberList.add(new ArrayList<>(newList)); | ||
| newList.clear(); | ||
| } | ||
| } | ||
| return newMemberList; | ||
| } | ||
|
|
||
| // ๊ฒฐ๊ณผ๋ฅผ ํ๋ฆฐํธ ํ๋ ํจ์์ ๋๋ค. | ||
| public void printResult(List<List<String>> result) { | ||
| System.out.println("์ค๋์ ์ง ์ถ์ฒ ๊ฒฐ๊ณผ์ ๋๋ค."); | ||
| for (List<String> line : result) { | ||
| StringBuilder sb = new StringBuilder(); | ||
| sb.append("[ "); | ||
| for (String s : line) { | ||
| sb.append(s).append(" | "); | ||
| } | ||
| sb.replace(sb.length()-2,sb.length(),"]"); | ||
| System.out.println(sb); | ||
| } | ||
|
Comment on lines
+78
to
+86
Member
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. StringJoiner์ ๋ํด ์์๋ณด๋ฉด ํธํด์ง๊ฑฐ์์! |
||
| System.out.println("์ถ์ฒ์ ์๋ฃํ์ต๋๋ค."); | ||
| } | ||
|
|
||
| public static Boolean isContinue() { | ||
| System.out.print("๋ค์ ๊ตฌ์ฑํ์๊ฒ ์ต๋๊น? (y or n): "); | ||
| try { | ||
| Scanner sc = new Scanner(System.in); | ||
| String continueFlag = sc.nextLine(); | ||
| if (continueFlag.equals("n")) { | ||
| System.out.println("์๋ฆฌ๋ฅผ ์ด๋ํด ์๋ก์๊ฒ ์ธ์ฌํด์ฃผ์ธ์."); | ||
| return false; | ||
| } else if (continueFlag.equals("y")) { | ||
| System.out.println("--------------------------------"); | ||
| return true; | ||
| } else { | ||
| throw new IllegalArgumentException("[ERROR] y ํน์ n๋ง ์ ๋ ฅํด์ฃผ์ธ์."); | ||
| } | ||
| } catch (Exception e) { | ||
| System.out.println(e.getMessage()); | ||
| return isContinue(); | ||
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
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.
while (isDone) {์ด๋ ๊ฒ ๊ตฌํํด๋ ๋์ง์์๊น์?