Skip to content

계산기 로직 구현 및 테스트 통과 ver.1#1

Open
SHINSEOJIN wants to merge 3 commits intoLikeLion-Study:mainfrom
SHINSEOJIN:shinseojin
Open

계산기 로직 구현 및 테스트 통과 ver.1#1
SHINSEOJIN wants to merge 3 commits intoLikeLion-Study:mainfrom
SHINSEOJIN:shinseojin

Conversation

@SHINSEOJIN
Copy link
Copy Markdown

로직 만들고, 구현해보는게 처음인지라 다각면에서 이리저리 봐주시면 감사드리겠습니다:)

@SHINSEOJIN SHINSEOJIN closed this Apr 3, 2025
@SHINSEOJIN SHINSEOJIN reopened this Apr 4, 2025
@SHINSEOJIN
Copy link
Copy Markdown
Author

로직 만들고, 구현해보는게 처음인지라 다각면에서 이리저리 봐주시면 감사드리겠습니다:)

Copy link
Copy Markdown
Member

@UiHyeon-Kim UiHyeon-Kim left a comment

Choose a reason for hiding this comment

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

1주차 고생하셨습니다~
요구 사항을 조금 더 확인해보고, 기본 요구 사항을 조금 더 지킬 수 있도록 해보면 좋을 것 같아요.

// TODO: 코드 구현
throw new IllegalArgumentException("아직 구현되지 않았습니다.");
int num = 0;
int number = 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

num과 number가 서로 무슨 역할을 하는지 헷갈릴 수 있을 것 같아요.
firstOperand, secondOperand처럼 서로 구분이 가도록 이름 짓는 연습을 하면 나중에 협업을 할 때도 도움이 될 거예요!

int num = 0;
int number = 0;
char operation = ' ';
StringBuilder sb = new StringBuilder();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

StringBuilder를 사용한 방법 정말 좋아요
String의 단점을 파악하고 사용하신 건가요? 궁금합니다

else if (operation == '-') num -= number;
else if (operation == '*') num *= number;
else if (operation == '/') num /= number;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

0으로 나눴을 때 오류가 나는데 이 부분도 오류를 처리해 준다면 더 좋을 것 같아요

} else if (ch == '+' || ch == '-' || ch == '*' || ch == '/') {

if (sb.length() == 0) {
System.out.println("숫자 없이 연산자가 들어왔습니다!");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

28번 줄에서 throw 처리해 준 것처럼 여기도 print가 아닌 throw 처리로 해준다면 조금 더 일관성이 있는 코드가 될 것 같아요.

Copy link
Copy Markdown

@daeun-ver daeun-ver left a comment

Choose a reason for hiding this comment

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

제가 작성한 코드와 크게 다르지않아 재밌었어요!
1주차 수고 많으셨습니다~

char operation = ' ';
StringBuilder sb = new StringBuilder();

input = input.trim().replaceAll("\\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.

공백 제거는 생각 못했었는데 덕분에 배워가요!

num *= number;
} else if (operation == '/') {
num /= number;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

switch-case문을 쓰면 더 깔끔해보여서 좋더라구요~

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