Skip to content

Conversation

@kdongd
Copy link
Owner

@kdongd kdongd commented Jan 13, 2026

작업 내용

  • Enum Operator를 사용하여 사칙연산 구현 (+, -, *, /)
  • StringCalculator 클래스에서 문자열로 입력받은 계산식을 순서대로 계산
  • 입력값은 공백으로 구분 (예: "2 + 3 * 4 / 5")
  • 잘못된 숫자 입력 시 예외 처리(NumberFormatException)

특징

  • 각 연산자는 Enum 상에서 operation 메서드 오버라이딩
  • 입력된 연산자를 Enum으로 변환하는 conversion 메서드 포함
  • 계산 결과 출력 후 종료
  • 메인 메소드 최소화

사용 방법

  • StringCalculatorMain 실행 후 계산식 입력

-메인메서드 최소화
-문자열 입력 메서드 생성
-문자열 분리 메서드 생성
-문자열 출력 메서드 생성
-실행 메서드 생성
-메인 메서드 최소화
-예외 추가
Copy link

@kakao-gray-great kakao-gray-great left a comment

Choose a reason for hiding this comment

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

고생하셨습니다.

comment 답변 부탁드리고 테스트 코드 작성도 해주세요~

-입력,출력,분리 클래스 생성
-예외 수정
-0으로 나눴을 때 처리(코멘트 못봤으예ㅜ)
Comment on lines 10 to 11
int result;
int number = Integer.parseInt(values[0]);

Choose a reason for hiding this comment

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

변수를 2개로 나눈 이유가 있을까요?

Copy link
Owner Author

Choose a reason for hiding this comment

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

number는 for문에서 중간 계산값을 저장, result는 number를 좀 더 쉽게 보여주기 위해 사용했습니다.
다시 생각해보니 result는 불필요한 변수인 것 같아서 바로 number를 return 하겠습니다.

Comment on lines 5 to 7
public String[] split(String formula) {
return formula.split(" ");
}

Choose a reason for hiding this comment

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

formula가 null이나 빈값이 들어오면 어떻게 되나요?

Copy link
Owner Author

@kdongd kdongd Jan 14, 2026

Choose a reason for hiding this comment

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

null값이 들어오면 NullPointerException이 발생
빈값이 들어오면 NumberFormatException이 발생합니다.
코드 수정 하겠습니다!

kdongd and others added 4 commits January 14, 2026 15:00
- int result 변수 삭제
- split 메서드 예외 추가
Updated README to reflect project requirements and design principles for the string calculator.
- 숫자 파싱 로직 메서드 분리(클래스로 분리하지 않은 이유는 독립적 기 능이 아니고StringCalculator클래스 내부에서 사용할 것 같아서 메서드로 생성했습니다. )
- main메서드 String 변수 이름 변경
- 입력 순서 연산 테스트
- 입력값 null 테스트
- 입력값 공백 테스트
- 0으로 나눴을때 테스트
- 숫자가 아닌 문자열 입력 테스트
- 지원하지 않는 연산자 입력 테스트
- 연산자 뒤에 숫자를 입력하지 않았을 때 테스트
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