Skip to content
Open
Show file tree
Hide file tree
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
89 changes: 86 additions & 3 deletions src/main/java/leets/leets_mate/LeetsMateApplication.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,121 @@
package leets.leets_mate;

import java.util.*;
import java.io.*;

public class LeetsMateApplication {

// ๋™์ž‘ ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
public void run() {
Scanner input = new Scanner(System.in); // Scanner ํด๋ž˜์Šค ์ƒ์„ฑ
int ret = 1; // loop ๋Œ๋ฆฌ๊ธฐ ์œ„ํ•œ ๋ณ€์ˆ˜ ์„ค์ •

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.

boolean ํƒ€์ž…์œผ๋กœ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•ด์ฃผ๋ฉด ์ข‹์•˜์„ ๊ฒƒ ๊ฐ™์•„์š”!


// ๋ฉค๋ฒ„ ์ด๋ฆ„ ์ž…๋ ฅ
System.out.println("๋ฉค๋ฒ„์˜ ์ด๋ฆ„์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”. (, ๋กœ ๊ตฌ๋ถ„)");
String members = input.nextLine();

// ์˜์–ด ์—†๋Š”์ง€ ํ™•์ธ
checkHasNoEnglish(members);

// ๋ฆฌ์ŠคํŠธ๋กœ ๋ฉค๋ฒ„ ๋ถ„๋ฆฌ
List<String> memArray = parseMembers(members);

// ๋ฉค๋ฒ„ ๋ช…์ˆ˜ ํ™•์ธ
int memberCount = memberNumber(memArray);

// ์ด๋ฆ„ ๊ฐœ์ˆ˜๋ณด๋‹ค ์ง ์ˆ˜๊ฐ€ ๋” ๋งŽ์œผ๋ฉด ์˜ˆ์™ธ๋ฐœ์ƒ
System.out.println("\n"+"์ตœ๋Œ€ ์ง ์ˆ˜๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.");
int maximumGroupSize = Integer.parseInt(input.nextLine());
checkDataValidity(memberCount, maximumGroupSize);

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 (ret == 1){
// ๋žœ๋ค ์ง๊ถ ์ถ”์ฒœ
printResult(generateRandomGroups(memArray, maximumGroupSize));

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.

ํ•ต์‹ฌ ๋กœ์ง์ด ์ˆจ์–ด์žˆ์–ด์š”~ ๐Ÿ˜ถโ€๐ŸŒซ๏ธ


System.out.print("\n"+"๋‹ค์‹œ ๊ตฌ์„ฑํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ? (y or n): ");
String re = input.nextLine();
System.out.println("--------------------------------");
ret = reGeneration(re);

if(ret != 1) break;
}

input.close();
}

// ๋ฌธ์ž์—ด๋กœ๋œ ๋ฉค๋ฒ„๋“ค์„ ๋ฆฌ์ŠคํŠธ๋กœ ๋ถ„๋ฆฌํ•˜๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
public List<String> parseMembers(String members) {

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.

return Arrays.asList(members.split(","));
์œ„ ์™€ ๊ฐ™์ด ์ž‘์„ฑํ•˜์‹œ๋ฉด ์‰ฝ๊ฒŒ ๋ถ„๋ฆฌ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

ChatGPT๋ฅผ ์ด์šฉํ•˜์—ฌ ์ฝ”๋“œ๋ฅผ ๋ถ™์—ฌ ๋„ฃ๊ณ  "๋” ์ข‹์€ ๋ฐฉ๋ฒ•์ด ์žˆ์„๊นŒ? ๋ฆฌํŒฉํ† ๋งํ•ด์ค˜' ์™€ ๊ฐ™์ด ์งˆ๋ฌธํ•˜์‹œ๋ฉด ์ข‹์€ ํ”ผ๋“œ๋ฐฑ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

๊ทธ๋ ‡๊ฒŒ๋„ ์ง€ํ”ผํ‹ฐ๋ฅผ ์‚ฌ์šฉํ•ด๋ณผ ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”!! ์ฐธ๊ณ ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค ใ…Žใ…Ž

return new ArrayList<>();
// ์ €์žฅํ•  ๋ฆฌ์ŠคํŠธ
List<String> memArray = new ArrayList<String>();

// ,๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋ฌธ์ž์—ด ๋ถ„๋ฆฌ
StringTokenizer st = new StringTokenizer(members, ",");

// ๋ฌธ์ž์—ด ๋ฆฌ์ŠคํŠธ์— ์ €์žฅ
while(st.hasMoreTokens())
memArray.add(st.nextToken());

return memArray;

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.

StringTokenizer๋„ ์ข‹์ง€๋งŒ, split()๋ฉ”์„œ๋“œ๋„ ํ˜„์žฌ ๋กœ์ง์—์„œ ์ƒ๋‹นํžˆ ๊ดœ์ฐฎ์•„ ๋ณด์ž…๋‹ˆ๋‹ค!

}

// ์ด ๋ฉค๋ฒ„์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
public int memberNumber(List<String> members) {
return 0;
return members.size();
}

// ๋ฉค๋ฒ„ ๋ฌธ์ž์—ด์— ์˜์–ด๊ฐ€ ์žˆ๋Š”์ง€ ๊ฒ€์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์˜์–ด๊ฐ€ ์žˆ๋‹ค๋ฉด ์˜ˆ์™ธ ์ถœ๋ ฅ
public void checkHasNoEnglish(String members) {
if (!members.matches("[๊ฐ€-ํžฃ,]+")) {

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 IllegalArgumentException("[ERROR] ์ด๋ฆ„์€ ํ•œ๊ธ€๋กœ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค");
}
}

// ๋ฉค๋ฒ„์ˆ˜์™€ ์ตœ๋Œ€ ์ง์ˆ˜ ๋ฐ์ดํ„ฐ๊ฐ€ ์œ ํšจํ•œ์ง€ ๊ฒ€์‚ฌํ•˜๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค. ์œ ํšจํ•˜์ง€ ์•Š๋‹ค๋ฉด ์˜ˆ์™ธ ์ถœ๋ ฅ
public void checkDataValidity(int memberCount, int maximumGroupSize) {
if (memberCount < maximumGroupSize) {
throw new IllegalArgumentException("[ERROR] ์ตœ๋Œ€ ์ง ์ˆ˜๋Š” ์ด๋ฆ„์˜ ๊ฐฏ์ˆ˜๋ณด๋‹ค ํด ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค");
}
}

// ๋žœ๋ค ์ง๊ฟ ์ถ”์ฒจํ•˜๋Š” ํ•จ์ˆ˜ ์ž…๋‹ˆ๋‹ค.
public List<List<String>> generateRandomGroups(List<String> memberList, int maximumGroupSize) {
return new ArrayList<>();
Collections.shuffle(memberList);
List<List<String>> groups = new ArrayList<>();
for (int i = 0; i < memberList.size(); i += maximumGroupSize) {
groups.add(new ArrayList<>(memberList.subList(i, Math.min(i + maximumGroupSize, memberList.size()))));

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.

๋‹ค๋ฅธ ์‚ฌ๋žŒ์ด ์‰ฝ๊ฒŒ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋„๋ก inline์œผ๋กœ ์‚ฌ์šฉํ•œ ๋กœ์ง์„ ์ง€์—ญ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด ๋ถ„๋ฆฌํ•ด๋ณด๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š”?

}
return groups;
}

// ๊ฒฐ๊ณผ๋ฅผ ํ”„๋ฆฐํŠธ ํ•˜๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
public void printResult(List<List<String>> result) {
System.out.println("\n"+"์˜ค๋Š˜์˜ ์ง ์ถ”์ฒœ ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค.");
for (List<String> group : result) {
System.out.print("[ ");
for (int i = 0; i < group.size(); i++) {
System.out.print(group.get(i));
if (i < group.size() - 1) {
System.out.print(" | ");
}
}
System.out.println(" ]");
}
Comment on lines +96 to +105

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 ๋˜๋Š” String.join()์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋ฉด ๋„์›€์ด ๋  ๊ฒƒ ๊ฐ™์•„์š” ๐Ÿ˜†

System.out.println("\n"+"์ถ”์ฒœ์„ ์™„๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค.");
}

// ๋‹ค์‹œ ์ถ”์ฒจ์„ ์ง„ํ–‰ํ•˜๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
public int reGeneration(String re) {

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.

ํ•จ์ˆ˜๋ช…์ด ํ•จ์ˆ˜์˜ ๊ธฐ๋Šฅ์„ ์ž˜ ์„ค๋ช…ํ•ด์ฃผ์ง€ ์•Š๋Š”๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!

getRetryDecision() ๊ฐ™์€๊ฑด ์–ด๋–จ๊นŒ์š”?
'๋‹ค์‹œ ์ถ”์ฒจํ• ์ง€ ๋ง์ง€ ์ž…๋ ฅ ๋ฐ›๋Š” ํ•จ์ˆ˜ ์ด๋ฆ„ ๋ญ๋ผ๊ณ  ํ• ๊นŒ?' ๋ผ๊ณ  GPT์—๊ฒŒ ๋ฌผ์–ด๋ณธ ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค!

if(re.equals("n")) {
System.out.println("์ž๋ฆฌ๋ฅผ ์ด๋™ํ•ด ์„œ๋กœ์—๊ฒŒ ์ธ์‚ฌํ•ด์ฃผ์„ธ์š”.");
return 0;
} else if (re.equals("y")) {
return 1;
} else {
throw new IllegalArgumentException("[ERROR] y๋˜๋Š” n์„ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค");
}
}

public static void main(String[] args) {
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/leets/leets_mate/LeetsMateApplicationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ void setUp() {
app.checkHasNoEnglish("welcome,to,leets");
});
}

@Test
void ๋‹ค์‹œ_์ถ”์ฒœ๋ฐ›์„๋•Œ_n๋˜๋Š”_y๋ฅผ_์ž…๋ ฅํ•œ๋‹ค() {
assertThrows(Exception.class, () -> {
app.reGeneration("no");
});
}
}