-
Notifications
You must be signed in to change notification settings - Fork 14
[BE] ์ธ์ง์ ๐ฅ ์ค๋์ ์ง๊ฟ์? #24
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
47a8728
87c7207
3e6eb85
e229e58
fce3927
c239796
765defc
d0011ae
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 |
|---|---|---|
| @@ -1,41 +1,126 @@ | ||
| package leets.leets_mate; | ||
|
|
||
| import leets.leets_mate.exception.InvalidInputException; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| public class LeetsMateApplication { | ||
| private static final String START_MESSAGE = "[Leets ์ค๋์ ์ง์๊ฒ]๋ฅผ ์์ํฉ๋๋ค.\n"; | ||
| private static final String GOODBYE_MESSAGE = "์ถ์ฒจ์ ์๋ฃํ์์ต๋๋ค.\n์๋ฆฌ๋ฅผ ์ด๋ํด ์๋ก์๊ฒ ์ธ์ฌํด์ฃผ์ธ์."; | ||
|
|
||
|
|
||
| public void run(){ | ||
| Scanner sc = new Scanner(System.in); | ||
|
|
||
| System.out.println(START_MESSAGE); | ||
| System.out.println("๋ฉค๋ฒ์ ์ด๋ฆ์ ์ ๋ ฅํด ์ฃผ์ธ์. (, ๋ก ๊ตฌ๋ถ)"); | ||
| String members = sc.nextLine(); | ||
|
|
||
| checkHasNoEnglish(members); | ||
| List<String> memberList = parseMembers(members); | ||
|
|
||
| int maximumGroupSize = getMaximumGroupSize(sc); | ||
|
|
||
|
|
||
| int memberCount = memberNumber(memberList); | ||
|
|
||
| checkDataValidity(memberCount, maximumGroupSize); | ||
|
|
||
| // ๋์ ํจ์์ ๋๋ค. | ||
| public void run() { | ||
| printResultAndMessage(memberList, maximumGroupSize); | ||
| while (askForRestart(sc)) { | ||
| System.out.println("--------------------------------"); | ||
| printResultAndMessage(memberList, maximumGroupSize); | ||
| } | ||
| sc.close(); | ||
| } | ||
|
|
||
| // ๋ฌธ์์ด๋ก๋ ๋ฉค๋ฒ๋ค์ ๋ฆฌ์คํธ๋ก ๋ถ๋ฆฌํ๋ ํจ์์ ๋๋ค. | ||
| public List<String> parseMembers(String members) { | ||
| return new ArrayList<>(); | ||
| return Arrays.asList(members.split(",")); | ||
| } | ||
| private int getMaximumGroupSize(Scanner sc) { | ||
| System.out.println("\n์ต๋ ์ง ์๋ฅผ ์ ๋ ฅํด ์ฃผ์ธ์."); | ||
| int maximumGroupSize = Integer.parseInt(sc.nextLine()); | ||
| if (maximumGroupSize <= 0) { | ||
| throw new InvalidInputException("[ERROR] ์ต๋ ์ง ์๋ 0๋ณด๋ค ์ปค์ผ ํฉ๋๋ค"); | ||
| } | ||
| return maximumGroupSize; | ||
| } | ||
|
|
||
| // ์ด ๋ฉค๋ฒ์๋ฅผ ๋ฐํํฉ๋๋ค. | ||
| public int memberNumber(List<String> members) { | ||
| return 0; | ||
| return members.size(); | ||
| } | ||
|
|
||
| // ๋ฉค๋ฒ ๋ฌธ์์ด์ ์์ด๊ฐ ์๋์ง ๊ฒ์ฌํฉ๋๋ค. ์์ด๊ฐ ์๋ค๋ฉด ์์ธ ์ถ๋ ฅ | ||
| public void checkHasNoEnglish(String members) { | ||
| public void checkHasNoEnglish(String members){ | ||
| if (members.matches(".*[a-zA-Z].*")) { | ||
| throw new InvalidInputException("[ERROR] ์ด๋ฆ์ ํ๊ธ๋ก ์ ๋ ฅํด์ผ ํฉ๋๋ค"); | ||
| } | ||
| if (members.isEmpty()) { | ||
| throw new InvalidInputException("[ERROR] ๋ฉค๋ฒ์ ์ด๋ฆ์ ์ ๋ ฅํด ์ฃผ์ธ์"); | ||
| } | ||
| } | ||
|
|
||
| // ๋ฉค๋ฒ์์ ์ต๋ ์ง์ ๋ฐ์ดํฐ๊ฐ ์ ํจํ์ง ๊ฒ์ฌํ๋ ํจ์์ ๋๋ค. ์ ํจํ์ง ์๋ค๋ฉด ์์ธ ์ถ๋ ฅ | ||
| public void checkDataValidity(int memberCount, int maximumGroupSize) { | ||
| public void checkDataValidity(int memberCount, int maximumGroupSize){ | ||
| if (maximumGroupSize <= 0) { | ||
| throw new InvalidInputException("[ERROR] ์ต๋ ์ง ์๋ 0๋ณด๋ค ์ปค์ผ ํฉ๋๋ค"); | ||
| } | ||
| if (maximumGroupSize > memberCount) { | ||
| throw new InvalidInputException("[ERROR] ์ต๋ ์ง ์๋ ์ด๋ฆ์ ๊ฐฏ์๋ณด๋ค ํด ์ ์์ต๋๋ค"); | ||
| } | ||
| } | ||
|
|
||
| // ๋๋ค ์ง๊ฟ ์ถ์ฒจํ๋ ํจ์ ์ ๋๋ค. | ||
| public List<List<String>> generateRandomGroups(List<String> memberList, int maximumGroupSize) { | ||
| return new ArrayList<>(); | ||
| Collections.shuffle(memberList); | ||
|
|
||
| List<List<String>> resultList = new ArrayList<>(); | ||
|
|
||
| int column = maximumGroupSize; | ||
| int row = (memberList.size() + column - 1) / column; | ||
|
|
||
|
|
||
| for (int i = 0; i < row; i++) { | ||
| resultList.add(new ArrayList<>()); | ||
| for (int j = i*column; j < column*(i+1); j++) { | ||
| if(j<memberList.size()) resultList.get(i).add(memberList.get(j)); | ||
| } | ||
| } | ||
| return resultList; | ||
|
Comment on lines
+75
to
+85
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. ๋ค์ค for ๋ฌธ์ ์ฌ์ฉํ๋ ๋ฐฉ์ ๋ง๊ณ ๋น ArrayList์ member๋ฅผ ๋ฃ์ด์ฃผ๋ค๊ฐ maximumGroupSize๊ฐ ๋๋ฉด ํด๋น ๋ฆฌ์คํธ๋ฅผ resultList์ ๋ฃ๋ ๋ฐฉ์๋ ๊ณ ๋ คํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค |
||
| } | ||
|
|
||
| // ๊ฒฐ๊ณผ๋ฅผ ํ๋ฆฐํธ ํ๋ ํจ์์ ๋๋ค. | ||
| public void printResult(List<List<String>> result) { | ||
| StringBuilder sb = new StringBuilder(); | ||
|
|
||
| for(int i=0; i<result.size(); i++){ | ||
| sb.append("[ "); | ||
| for(int j=0; j<result.get(i).size(); j++){ | ||
| sb.append(result.get(i).get(j)); | ||
| if(j<result.get(i).size()-1) sb.append(" | "); | ||
| } | ||
| sb.append(" ]"); | ||
| sb.append("\n"); | ||
| } | ||
| System.out.println(sb); | ||
| } | ||
|
Comment on lines
88
to
+101
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 ์ฌ์ฉ๋ ๊ณ ๋ คํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค!! |
||
| public void printResultAndMessage(List<String> memberList, int maximumGroupSize) { | ||
| List<List<String>> lists = generateRandomGroups(memberList, maximumGroupSize); | ||
| System.out.println("\n์ค๋์ ์ง ์ถ์ฒ ๊ฒฐ๊ณผ์ ๋๋ค."); | ||
| printResult(lists); | ||
| System.out.println(GOODBYE_MESSAGE); | ||
| } | ||
| public boolean askForRestart(Scanner sc) { | ||
| while (true) { | ||
| System.out.print("๋ค์ ๊ตฌ์ฑํ์๊ฒ ์ต๋๊น? (y or n): "); | ||
| String retry = sc.nextLine().trim().toLowerCase(); | ||
| if (retry.equals("n")) { | ||
| System.out.println("์๋ฆฌ๋ฅผ ์ด๋ํด ์๋ก์๊ฒ ์ธ์ฌํด์ฃผ์ธ์."); | ||
| return false; | ||
| } else if (retry.equals("y")) { | ||
| return true; | ||
| } else { | ||
| throw new InvalidInputException("[ERROR] ์๋ชป๋ ์ ๋ ฅ์ ๋๋ค. 'y' ๋๋ 'n'์ ์ ๋ ฅํด์ฃผ์ธ์."); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| public static void main(String[] args) throws Exception { | ||
| LeetsMateApplication app = new LeetsMateApplication(); | ||
| app.run(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package leets.leets_mate.exception; | ||
|
|
||
| public class InvalidInputException extends RuntimeException{ | ||
| public InvalidInputException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| } |
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.
์ถ๋ ฅ ๋ฉ์์ง๋ฅผ System.out.println("์ถ์ฒจ์ ์๋ฃํ์์ต๋๋ค"); ์ด๋ฐ ์์ด ์๋ ๋ฐ๋ก ๋ณ์๋ก ์ง์ ํ์ฌ System.out.println(GOODBYE_MESSAGE); ์ด๋ฐ ์์ผ๋ก ํ์ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค!!