Skip to content

[문자열 덧셈 계산기] 김수현 미션 제출합니다.#212

Open
suhyun113 wants to merge 10 commits intowoowacourse-precourse:mainfrom
suhyun113:suhyun113
Open

[문자열 덧셈 계산기] 김수현 미션 제출합니다.#212
suhyun113 wants to merge 10 commits intowoowacourse-precourse:mainfrom
suhyun113:suhyun113

Conversation

@suhyun113
Copy link
Copy Markdown

📝 프로젝트 개요

사용자가 입력한 문자열에서 숫자를 추출하고 합계를 계산하는 프로그램

  • 기본 구분자(,, :)와 커스텀 구분자(//;\n1;2;3 형식) 모두 지원
  • 숫자가 아닌 값 또는 음수 값이 포함될 경우 예외 발생

🌿 주요 구현 내용

  1. App 클래스 : 프로그램 진입점
  2. InputParser 클래스 : 입력 문자열을 숫자 배열로 변환
  3. InputValidator 클래스 : 숫자 배열에 대한 유효성 검사
  4. Calculator 클래스 : 숫자 배열의 합 계산

⚠️ 예외 처리 내용

  • 숫자가 아닌 값 포함 : [ERROR] 숫자가 아닌 값이 포함되어 있습니다.
  • 0 또는 음수 포함 : [ERROR] 양수가 아닌 값이 포함되어 있습니다.
  • 잘못된 커스텀 구분자 형식 : [ERROR] 잘못된 커스텀 구분자 형식입니다.
  • 빈 입력 : 결과 0 반환

📷테스트 결과

  • 기본 구분자 계산
    image

  • 커스텀 구분자 계산
    image

  • 0 또는 음수 포함
    image

  • 잘못된 커스텀 구분자 형식
    image

🔧 개선 및 회고

  • 테스트 진행 중, 현재 커스텀 구분자는 단일 문자만 지원한다는 것을 알게되었습니다. 다중 문자(//;;\n1;;2;;3)의 경우에도 잘 작동한다면 좋을 것 같다는 생각이 들었습니다.

Copy link
Copy Markdown

@janghw0126 janghw0126 left a comment

Choose a reason for hiding this comment

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

1주차 미션 정말 수고많으셨어요! 🥹

전체적으로 코드 구조가 정말 깔끔했고, 역할 분리도 명확해서 읽기 편했습니다. 특히 InputParser, InputValidator, Calculator로 나눈 흐름이 직관적이라 전체 동작이 한눈에 들어왔어요! 정규식을 활용해 커스텀 구분자와 특수문자까지 안전하게 처리한 부분도 인상적이었습니다.

다음 2주차도 함께 파이팅 해봐요!🥰😆

Comment thread src/InputParser.js
// 커스텀 구분자
if (raw.startsWith("//")) {
const match =
raw.match(/^\/\/(.)\n(.*)/s) || // 실제 줄바꿈
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

match를 활용해 커스텀 구분자를 이렇게 더 깔끔하게 파싱할 수 있었군요! 새로운 방법을 알아갑니다😊

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

커스텀 구분자를 한 글자만 인식하도록 되어 있는데, 혹시 여러 글자 구분자도 고려해볼 수 있을까요? 정규식을 확장한다면 어떤 식으로 바꿀 수 있을지 궁금합니다🧐

Comment thread src/InputParser.js
numbersPart = rest;
}

const escaped = delimiters.map((d) => d.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
Copy link
Copy Markdown

@janghw0126 janghw0126 Oct 22, 2025

Choose a reason for hiding this comment

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

구분자에 특수문자가 포함될 수도 있다는 점을 고려해 정규식을 이렇게 안전하게 생성할 수도 있군요! 덕분에 escape 처리를 활용하는 방법을 배워갑니다 😊

Comment thread src/InputValidator.js
}

// 양수가 아닌 값(0 또는 음수)
const hasNegative = numbers.some((n) => n <= 0);
Copy link
Copy Markdown

@janghw0126 janghw0126 Oct 22, 2025

Choose a reason for hiding this comment

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

n <= 0 조건으로 0도 제외하신 이유가 궁금합니다! 과제 요구사항 상 음수만 금지인데, 0까지 제한하신 이유가 있으실까요?

Comment thread src/InputParser.js
// 숫자 배열로 변환
return numbersPart
.split(regex)
.map((token) => token.trim())
Copy link
Copy Markdown

@janghw0126 janghw0126 Oct 22, 2025

Choose a reason for hiding this comment

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

const raw = (input || "").trim();

입력 전체와 각 토큰에 대해 각각 trim()을 적용하신 게 좋은 것 같아요! 혹시 입력 앞뒤 공백뿐 아니라, 숫자 사이에 실수로 들어간 공백도 잘 처리하려고 trim()을 두 번 쓴 건가요?

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.

2 participants