Skip to content

[BCSD Lab] 박태진, 1차시 미션 제출합니다. #107

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

Open
wants to merge 13 commits into
base: taejinn
Choose a base branch
from

Conversation

taejinn
Copy link

@taejinn taejinn commented Jul 31, 2025

안녕하세요?

1차시 미션을 완료하여 제출합니다.

Copy link

@asa9874 asa9874 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다.🥳
코드에 대한 제 생각을 작성해보았습니다.

혹시 추가적으로 더 논의할 점이나, 제 생각과 다른 의견이 있으시면 언제든지 말씀해 주세요! 😊

Comment on lines 18 to 20
if (a == 0 || b == 0) {
throw new IllegalArgumentException("0 으로 나눌 수 없습니다.");
}
Copy link

Choose a reason for hiding this comment

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

해당 부분에서 a(분자) 부분은 0이여도 지장없을거같습니다.

Copy link
Author

Choose a reason for hiding this comment

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

앗 확인해보니 그렇네요😅 수정하도록 하겠습니다!


public class StringCalc {

private static final String defaultDelimiters = "[,:]";
Copy link

Choose a reason for hiding this comment

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

자바에서 상수의 경우 UPPER_CASE_WITH_UNDERSCORES 컨벤션으로 작성하는 것을 권고하고있습니다.
해당 링크 참고해주시면 좋을거같아요

Copy link
Author

Choose a reason for hiding this comment

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

알려주셔서 감사합니다😀

int res = a / b;
return res;
}
}
Copy link

Choose a reason for hiding this comment

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

파일 끝에 개행 문자가 없어서 EOF 문제가 발생하고있습니다.
EOF에 대해 찾아 보시면 좋을것같습니다.

Comment on lines 8 to 45
public int add(String text) {
if (text == null || text.isEmpty()) {
return 0;
}

String delimiters = defaultDelimiters;
String actualTextToParse = text;

Pattern customDelimiterPattern = Pattern.compile("//(.)\n(.*)");
Matcher matcher = customDelimiterPattern.matcher(text);

if (matcher.find()) {
String customDelimiter = Pattern.quote(matcher.group(1));
delimiters = customDelimiter;
actualTextToParse = matcher.group(2);
}

String[] numbersAsString = actualTextToParse.split(delimiters);
int sum = 0;

for (String numStr : numbersAsString) {
if (numStr.isEmpty()) {
continue;
}

try {
int number = Integer.parseInt(numStr);

if (number < 0) {
throw new RuntimeException("음수는 입력할 수 없습니다.");
}
sum += number;
} catch (NumberFormatException e) {
throw new RuntimeException("숫자 이외의 값이 포함되어 있습니다.");
}
}
return sum;
}
Copy link

Choose a reason for hiding this comment

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

add 메서드가 기능들을 많이 소유하고 있어 현재 단일 책임 원칙(SRP)을 위배하는거 같습니다.
기능들을 다양한 메서드로 분리해보는것도 좋을거같습니다.

Comment on lines +16 to +17
Pattern customDelimiterPattern = Pattern.compile("//(.)\n(.*)");
Matcher matcher = customDelimiterPattern.matcher(text);
Copy link

Choose a reason for hiding this comment

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

자바에서 제공하는 정규표현식 패키지를 사용하셨네요 👍

Comment on lines 5 to 6

private static final String defaultDelimiters = "[,:]";
Copy link

Choose a reason for hiding this comment

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

다른 클래스와 다르게 해당 클래스에서만 첫줄 개행이 이뤄지고있습니다.
해당 부분은 컨벤션 통일 해주시면 좋을거같아요.

@@ -0,0 +1,24 @@
public class Calc {
public int add(int a, int b) {
int res = a + b;
Copy link

Choose a reason for hiding this comment

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

아래처럼 한번에 리턴하지 않고 변수에 저장해서 리턴하는 이유가 있을까요?

return a + b;

Copy link
Author

Choose a reason for hiding this comment

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

결과 값을 res 변수에 저장하는 것이 습관이 되어서 해당 형식으로 작성했습니다!


if (matcher.find()) {
String customDelimiter = Pattern.quote(matcher.group(1));
delimiters = customDelimiter;
Copy link

Choose a reason for hiding this comment

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

기본 구분자와 커스텀 구분자가 섞여있는 경우 기본 구분자가 숫자 이외의 값으로 분류되는 것으로 보이는데 어떻게 처리하는게 좋다고 생각하시나요?

  1. 커스텀 구분자가 있으면 기본 구분자는 숫자 이외의 값이다.
  2. 기본 구분자 + 커스텀 구분자로 나눠야 한다.

e.g. //@\n1@2,3:4의 결과는?

  1. RuntimeException("숫자 이외의 값이 포함되어 있습니다.");
  2. 10

저는 개인적으로 2번이 맞다고 생각합니다.

Copy link
Author

Choose a reason for hiding this comment

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

저는 커스텀 구분자와 기본 구분자가 함께 사용될 경우, 커스텀 구분자만 유효한 것으로 간주해야 한다고 가정하고 코드를 작성했습니다. 하지만, 지금 다시 보니 말씀해주신 부분이 더 맞는 것 같습니다. 지금 수정 후 커밋하였습니다!~

감사합니다.

if (number < 0) {
throw new RuntimeException("음수는 입력할 수 없습니다.");
}
sum += number;
Copy link

Choose a reason for hiding this comment

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

오버플로우도 생각해보면 좋을거 같아요

Copy link
Author

Choose a reason for hiding this comment

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

오..! 조언해주셔서 감사합니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants