[4기 - 박현지] 1~2주차 과제: 계산기 구현 미션 제출합니다. #185
Open
hyeon-z wants to merge 18 commits intoprgrms-be-devcourse:hyeon-zfrom
Open
[4기 - 박현지] 1~2주차 과제: 계산기 구현 미션 제출합니다. #185hyeon-z wants to merge 18 commits intoprgrms-be-devcourse:hyeon-zfrom
hyeon-z wants to merge 18 commits intoprgrms-be-devcourse:hyeon-zfrom
Conversation
feat: 계산기 구현
chore: package이름 수정
Hunkik
reviewed
Jun 15, 2023
There was a problem hiding this comment.
계산기 과제 고생하셨습니다. 코멘트 참고해주세요
- 메서드에 코드가 길어진다면, 길어진 부분을 기능적으로 하나로 묶어서 다시 메서드로 만들면 됩니다! 재사용성이 없다면, private로 내부에, 아니라면 더 고려해서 짜시면 될 것 같아여
- 객체지향적으로 짰다고 하기는 조금 애매한것같습니다. 이후에 확장이나 재사용성, 협력, SOLID원칙 등을 봤을때 지켜지지 않는 부분이 많아서 이를 고려해서 생각해보시면 좋을것같아여. 예를들면 main에서 Input,Output,Storage를 DI를 통해 추후 다른 Input으로 구현체가 변경되어도 서비스로직은 그대로 유지한다던가 하는 방식이 있곘네요
- 테스트 코드에서는 굳이 안쓰셔도 될것같아여! 최대한 다양한 케이스를 테스트 한다고 생각하는게 더 중요하다고 생각합니다.
- 굳이 많이 안쓰인다면 validation 쓰는곳 바로 아래에 private 메서드로 쓰시는게 더 좋아보입니다.
| int choice = checkChoiceNum(Integer.parseInt(br.readLine())); | ||
| System.out.println(); | ||
|
|
||
| if (choice == 0) { |
|
|
||
| br = new BufferedReader(new InputStreamReader(System.in)); | ||
| int choice = checkChoiceNum(Integer.parseInt(br.readLine())); | ||
| System.out.println(); |
There was a problem hiding this comment.
굳이 필요할까 싶습니다! checkChoiceNum 이후 필요한거면 거기에 넣어도 될것같아여
Comment on lines
+37
to
+38
| br = new BufferedReader(new InputStreamReader(System.in)); | ||
| String expression = br.readLine(); |
There was a problem hiding this comment.
버퍼리더 close하는곳이 없네여! 버퍼는 쓰고 닫는 습관이 있으면 좋다고 생각합니다. 리더를 열고 닫는 곳은 선택에 맡기겠습니다 ㅎㅎ
| import static validator.Validator.checkValidOperator; | ||
|
|
||
| public class Calculation { | ||
| Operator operator; |
Comment on lines
+29
to
+34
| Stack<Character> stack = new Stack<>(); | ||
| StringBuilder sb = new StringBuilder(); | ||
|
|
||
| String[] split = expression.split(" "); | ||
|
|
||
| for (String now : split) { |
|
|
||
| char c = checkValidOperator(now.charAt(0)); | ||
|
|
||
| switch (c) { |
| } | ||
|
|
||
| private static boolean isDigit(String str) { | ||
| return str.matches(positiveRegularExp); |
| @@ -0,0 +1,24 @@ | |||
| package operator; | |||
|
|
|||
| public class Operator implements Add, Subtract, Divide, Multiply { | |||
There was a problem hiding this comment.
Add, Subtract, Divide, Multiply같은경우에 interface로 만든 이유가 있나요?
Comment on lines
+3
to
+11
| public class Choice { | ||
| public static void printChoice() { | ||
| System.out.println("0. 종료"); | ||
| System.out.println("1. 조회"); | ||
| System.out.println("2. 계산"); | ||
|
|
||
| System.out.println(); | ||
| System.out.print("선택: "); | ||
| } |
There was a problem hiding this comment.
프린트로 패키지를 나누셨는데 Choice만 있는게 뭔가 어색해보이네요! 결과 같은경우도 print할 수 있고, 다양한 경우가 있는데 Choice만 있는 이유가 있을까요?
|
고생 하셨습니다.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 과제 설명
요구사항
👩💻 요구 사항과 구현 내용
각 연산자 interface 구현
더하기, 빼기, 곱하기, 나누기를 interface로 구현하여 operator package에 포함했습니다.
연산자 클래스 구현
각 연산자 interface를 구현하는 연산자 클래스를 operator package에 포함했습니다.
선택 항목 출력하는 Choice 클래스 구현
콘솔에 선택 항목을 출력하넌 Choice클래스를 구현했습니다.
계산기 기능 - 계산 구현
계산기 기능 중 하나인 계산을 담당하는 클래스를 구현하였습니다.
중위표현식을 후위 표현식으로 변환하는 메서드와 후위 표현식으로 결과를 구하는 메서드로 이루어져 있습니다.
계산기 기능 - 저장 구현
Map을 통해 계산기 계산 기록을 저장하는 클래스를 구현하였습니다.
계산 기록을 저장하는 메서드와 전체 계산 이력을 출력하는 메서드로 이루어져있습니다.
계산기 클래스 구현
반복하며 계산기를 동작시키는 클래스를 구현하였습니다.
Main함수 구현
계산기 객체를 생성하여 동작시켰습니다.
테스트 코드
두 가지 종류의 테스트 코드로 구현했습니다.
전체구조
Add, Subtract, Divide, Multiply interface를 구현하는 Operator클래스
생성자로 Operator를 초기화하는 Caculation(계산)클래스
생성자로 Caculation, Storage를 초기화하는 Calculator(계산기)클래스
✅ 피드백 반영사항
✅ PR 포인트 & 궁금한 점