-
Notifications
You must be signed in to change notification settings - Fork 0
문자열 계산기 #1
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
base: main
Are you sure you want to change the base?
문자열 계산기 #1
Conversation
-문자열 입력 메서드 생성 -문자열 분리 메서드 생성 -문자열 출력 메서드 생성 -실행 메서드 생성 -메인 메서드 최소화 -예외 추가
kakao-gray-great
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다.
comment 답변 부탁드리고 테스트 코드 작성도 해주세요~
-입력,출력,분리 클래스 생성 -예외 수정
-0으로 나눴을 때 처리(코멘트 못봤으예ㅜ)
| int result; | ||
| int number = Integer.parseInt(values[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
변수를 2개로 나눈 이유가 있을까요?
There was a problem hiding this comment.
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 하겠습니다.
| public String[] split(String formula) { | ||
| return formula.split(" "); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formula가 null이나 빈값이 들어오면 어떻게 되나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null값이 들어오면 NullPointerException이 발생
빈값이 들어오면 NumberFormatException이 발생합니다.
코드 수정 하겠습니다!
- int result 변수 삭제 - split 메서드 예외 추가
Updated README to reflect project requirements and design principles for the string calculator.
- 숫자 파싱 로직 메서드 분리(클래스로 분리하지 않은 이유는 독립적 기 능이 아니고StringCalculator클래스 내부에서 사용할 것 같아서 메서드로 생성했습니다. ) - main메서드 String 변수 이름 변경
- 입력 순서 연산 테스트 - 입력값 null 테스트 - 입력값 공백 테스트 - 0으로 나눴을때 테스트 - 숫자가 아닌 문자열 입력 테스트 - 지원하지 않는 연산자 입력 테스트 - 연산자 뒤에 숫자를 입력하지 않았을 때 테스트
작업 내용
Operator를 사용하여 사칙연산 구현 (+, -, *, /)StringCalculator클래스에서 문자열로 입력받은 계산식을 순서대로 계산특징
operation메서드 오버라이딩conversion메서드 포함사용 방법
StringCalculatorMain실행 후 계산식 입력