Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 75 additions & 3 deletions src/main/java/leets/leets_mate/LeetsMateApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Comment on lines +17 to +20

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while (isDone) { ์ด๋ ‡๊ฒŒ ๊ตฌํ˜„ํ•ด๋„ ๋˜์ง€์•Š์„๊นŒ์š”?

}
}

// ๋ฌธ์ž์—ด๋กœ๋œ ๋ฉค๋ฒ„๋“ค์„ ๋ฆฌ์ŠคํŠธ๋กœ ๋ถ„๋ฆฌํ•˜๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
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(","))) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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) {
Expand Down