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
1 change: 1 addition & 0 deletions leets-mate-java-1
Submodule leets-mate-java-1 added at b0b5c2
60 changes: 57 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,87 @@ public class LeetsMateApplication {

// ๋™์ž‘ ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
public void run() {
Scanner scanner=new Scanner(System.in);
try{
System.out.println("๋ˆ„๊ตฌ๋ˆ„๊ตฌ์žˆ์–ด?");

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.

์š”๊ตฌ์‚ฌํ•ญ์— ๋งž๊ฒŒ ์ž‘์„ฑํ•ด์ฃผ์‹œ๋ฉด ๋” ์ข‹์„๊ฒƒ ๊ฐ™์•„์š”!

String leetsMember=scanner.nextLine();
checkHasNoEnglish(leetsMember);

List<String> membersList=parseMembers((leetsMember));

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.println("๋ช‡๋ช…์”ฉํ• ๋ž˜?");
int groupNum=scanner.nextInt();
checkDataValidity(membersList.size(),groupNum);

List<List<String>> leetsGroup=generateRandomGroups(membersList,groupNum);

System.out.println("๊ฒฐ๊ณผ์•ผ.");
printResult(leetsGroup);

while(true){
System.out.println("๋งˆ์Œ์— ์•ˆ๋“ค์–ด?(y/n)");
String answer=scanner.next();
Comment on lines +27 to +28

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.

print("")ํ›„ nextLine()์„ ์ž…๋ ฅ๋ฐ›๋Š” ๊ฒƒ์ด ๊ฐ€๋…์„œ์ด ์ข€ ๋” ์ข‹์•„๋ณด์ž…๋‹ˆ๋‹ค!

if(answer.equalsIgnoreCase("y")){
leetsGroup=generateRandomGroups(membersList,groupNum);
printResult(leetsGroup);
}
else if(answer.equalsIgnoreCase("n")){
break;
}
}
Comment on lines +26 to +36

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.

์˜๋ฌธ y์™€ n ์ด์™ธ์˜ ๊ฐ’์ด ๋“ค์–ด์™”์„๋•Œ์˜ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๊ฐ€ ์—†๋Š”๊ฒƒ ๊ฐ™์€๋ฐ, ์ข€๋” ๊ตฌ์ฒด์ ์ธ ์—๋Ÿฌ ๋กœ์ง์„ ์ถ”๊ฐ€ํ•˜๋Š”๊ฒŒ ์–ด๋–จ๊นŒ์š”?

}catch(IllegalArgumentException e){
System.out.println("[ERROR]"+ e.getMessage());
run();
}finally{
scanner.close();
}
Comment on lines +37 to +42

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.

e๋กœ ๋„˜๊ฒจ์ฃผ๋Š” ๊ฒƒ๋ณด๋‹ค๋Š” ๊ตฌ์ฒด์ ์ธ ์ผ€์ด์Šค์— ๋”ฐ๋ผ์„œ ์—๋Ÿฌ๋ฉ”์‹œ์ง€๋ฅผ ๋„ฃ๋Š”๊ฒƒ์ด ์ข€๋” ์ข‹์„๊ฒƒ ๊ฐ™์•„์š”

}
Comment on lines +26 to 43

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<String> parseMembers(String members) {
return new ArrayList<>();
List<String> memberList=new ArrayList<>();
String[] divide=members.split(",");

@jj0526 jj0526 Apr 11, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์‚ฌ๋žŒ1, ์‚ฌ๋žŒ2, (๋„์–ด์“ฐ๊ธฐ 2๊ฐœ) ์‚ฌ๋žŒ3,์‚ฌ๋žŒ4, ์‚ฌ๋žŒ5
์ด๋ ‡๊ฒŒ ๋„์–ด์“ฐ๊ธฐ๊ฐ€ 0๊ฐœ, 1๊ฐœ, n๊ฐœ์ธ ๊ฒฝ์šฐ์—์„œ ์ด๋ฆ„๋งŒ ์ถœ๋ ฅ๋  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋ฉด ์ข‹์„๊ฑฐ๊ฐ™์•„์š”

for(String member:divide){
memberList.add(member);
}
return memberList;
}

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

// ๋ฉค๋ฒ„ ๋ฌธ์ž์—ด์— ์˜์–ด๊ฐ€ ์žˆ๋Š”์ง€ ๊ฒ€์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์˜์–ด๊ฐ€ ์žˆ๋‹ค๋ฉด ์˜ˆ์™ธ ์ถœ๋ ฅ
public void checkHasNoEnglish(String members) {
if(members.matches(".*[a-zA-Z].*")){
throw new IllegalArgumentException("์˜์–ด๊ฐ€ ๋“ค์–ด๊ฐ€๋ฉด ์•ˆ๋œ๋‹ค.");
}
Comment on lines +62 to +64

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 void checkDataValidity(int memberCount, int maximumGroupSize) {
if(memberCount<=0||maximumGroupSize<=0||maximumGroupSize>memberCount){
throw new IllegalArgumentException(("๋ฉค๋ฒ„์ˆ˜์™€ ์ตœ๋Œ€์ง์ˆ˜ ๋ฐ์ดํ„ฐ๊ฐ€ ์œ ํšจํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."));
}
}

// ๋žœ๋ค ์ง๊ฟ ์ถ”์ฒจํ•˜๋Š” ํ•จ์ˆ˜ ์ž…๋‹ˆ๋‹ค.
public List<List<String>> generateRandomGroups(List<String> memberList, int maximumGroupSize) {
return new ArrayList<>();
List<String> afterMembers = new ArrayList<>(memberList);
Collections.shuffle(afterMembers);
List<List<String>> groups = new ArrayList<>();
Comment on lines +76 to +78

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.

List๋ฅผ ์—ฌ๋Ÿฌ๋ฒˆ ์„ ์–ธํ•˜๋Š”๊ฒƒ๋ณด๋‹ค ๋ถˆํ•„์š”ํ•œ ์ฝ”๋“œ๋ฅผ ์ค„์ด๋Š”๊ฒŒ ์–ด๋–จ๊นŒ์š”? groups๋งŒ ์‚ฌ์šฉํ•˜๋ฉด ์ข€๋” ๊ฐ„๊ฒฐํ•œ ์ฝ”๋“œ๊ฐ€ ๋ ๊ฑฐ๊ฐ™์•„์š”!

for(int i=0;i<afterMembers.size();i+=maximumGroupSize){
groups.add(afterMembers.subList(i,Math.min(i+maximumGroupSize,afterMembers.size())));
}
Comment on lines +79 to +81

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 groups;
}

// ๊ฒฐ๊ณผ๋ฅผ ํ”„๋ฆฐํŠธ ํ•˜๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
public void printResult(List<List<String>> result) {
for(int i=0;i<result.size();i++){
System.out.println(result.get(i));
}
Comment on lines +87 to +89

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.

["์ด๋ฆ„" | "์ด๋ฆ„"] ํ•ด๋‹น๊ณผ ๊ฐ™์€ ํ˜•ํƒœ๋กœ ์ถœ๋ ฅํ•ด์•ผํ•˜๋Š”๋ฐ, println์œผ๋กœ ์ถœ๋ ฅํ•˜๋ฉด ๋ฆฌ์ŠคํŠธ๋กœ ์ถœ๋ ฅ์ด ๋ ๊ฑฐ๊ฐ™์€๋ฐ, ์š”๊ตฌ์‚ฌํ•ญ์— ๋งž๊ฒŒ printํ•จ์ˆ˜๋ฅผ ๋‹ค์‹œ ๊ตฌ์„ฑํ•˜๋Š”๊ฒŒ ์–ด๋–จ๊นŒ์š”?

}

public static void main(String[] args) {
Expand Down