Skip to content

solve problem 01.calculator by seoyoung#1

Open
sss20young wants to merge 2 commits into
threeracha:mainfrom
sss20young:main
Open

solve problem 01.calculator by seoyoung#1
sss20young wants to merge 2 commits into
threeracha:mainfrom
sss20young:main

Conversation

@sss20young

Copy link
Copy Markdown
Member

Calculator.java & CalculatorTest.java

[ 문제점 ]

  1. 우선 함수를 어느 정도까지 잘게 나눠야 하는지에 대해 익숙하지 않은 것 같습니다.
  2. 간단한 코드이지만, TestCode를 짜는 것이 처음이라 예외처리 관련 부분은 어떤식으로 짜야하는 지 모르겠습니다.

현재까지 리뷰 부탁드리겠습니다.

if (st.hasMoreTokens())
operand = stringToInteger(st.nextToken());

if (operator == '+')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

public static final String ADD = "+";
이런식으로 상단에 상수처리 할 수 있습니다.


public static void main(String[] args) throws IOException {
try {
br = new BufferedReader(new InputStreamReader(System.in));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Scanner 를 이용하면 더 간단하게 할 수 있어요

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

과거 알고리즘 문제를 풀 때,
Scanner의 입력의 제한으로 인해 BufferedReader를 사용했던 기억이 있어서 해당 클래스를 사용했습니다.

if (operator == '/')
result = divide(result, operand);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

사칙연산에 있는 문자가 없다면
throw new IllegalArgumentException("사칙연산 문자가 아닙니다");
이런식으로 처리할 수 있겠네요

@Test
void testStringToChar() {
// TODO: 사칙연산
assertThatIllegalArgumentException().isThrownBy(() -> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

아래와 같은 형식으로 할수 있어요

assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(
() -> {
calculator.judge(str);
}
).withMessageMatching("문자열이 비어있습니다.");

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