Conversation
sosow0212
left a comment
There was a problem hiding this comment.
수고하셨습니다!
미션 요구사항이 지켜지지 않은 것 같은데 한 번 확인 부탁드릴게요
정렬 습관화 들이면 더 좋을 것 같습니다!
| import simpleCalculator.view.CalculatorView; | ||
| import java.util.List; | ||
|
|
||
| public class CalculatorController { |
| public void doAdd() { | ||
| int addResult = calculator.addNumbers(); | ||
| System.out.println("덧셈 결과 : " + addResult); | ||
| } | ||
|
|
||
| public void doSub(){ | ||
| int subResult = calculator.subNumbers(); | ||
| System.out.println("뺄셈 결과 : " + subResult); | ||
| } | ||
|
|
||
| public void doDivide(){ | ||
| int divideResult = calculator.divideNumbers(); | ||
| System.out.println("나눗셈 결과 : " + divideResult); | ||
| } | ||
|
|
||
| public void doMultiple(){ | ||
| int multipleResult = calculator.multipleNumbers(); | ||
| System.out.println("곱셈 결과 : " + multipleResult); | ||
| } |
There was a problem hiding this comment.
사용자의 입력에 따라서 곱셈인지 뺄셈인지 등등 나뉘어야할 것 같아요
지금은 모든 결과를 출력하는데 다른 방식으로 해야할 것 같아요
There was a problem hiding this comment.
따로 결과를 출력하는 OutputView로 분리하여 출력하도록 수정하겠습니다.
| private final int num1; | ||
| private final int num2; | ||
|
|
||
| public Calculator(int num1, int num2){ |
| return num1 - num2; | ||
| } | ||
|
|
||
| public int divideNumbers(){ |
There was a problem hiding this comment.
- 모든 코드들 정렬했습니다!
- 나누는 수가 0일 때 예외 처리 진행했습니다!
| public int multipleNumbers(){ | ||
| return num1 * num2; | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
EOF에 대해 맞게 이해 했는지와 궁금한 점이 생겼습니다.
입력의 개수가 정해지지 않은 경우에만 더 이상 입력이 없게 하기 위해 사용하는 것으로 이해했습니다.
scanner.close()와 차이점이 무엇인가요??
There was a problem hiding this comment.
scanner.close()는 resource를 풀어주는 거라 다른 결이긴 합니다!
해당 링크 참고해보시면 좋을 것 같아요!
| return number; | ||
| } | ||
|
|
||
| public int sum(int[] inputList){ |
There was a problem hiding this comment.
메서드 네이밍이 헷갈려서 그런가요??
아니면 필요 없는 메서드라고 생각하셔서 그러신 걸까요??
해당 메서드는 배열 안의 요소를 합하는 메서드라 필요하다고 생각했습니다!
혹시 메서드 명이 문제라면 수정하도록 하겠습니다.
| int testNum1 = 2; | ||
| int testNum2 = 1; | ||
| Calculator calculator = new Calculator(testNum1, testNum2); |
| void addTest(){ | ||
| //given | ||
| int expectValue = 3; | ||
| int testAdd = calculator.addNumbers(); |
| int testNum1 = 2; | ||
| int testNum2 = 1; | ||
| Calculator calculator = new Calculator(testNum1, testNum2); | ||
| @DisplayName("더하기 테스트 1") |
| @@ -0,0 +1,57 @@ | |||
| package stringCalcculator.model; | |||
There was a problem hiding this comment.
패키지 명 오타났네요!
그리고 다른 패키지에 둔 이유가 있을까요?
There was a problem hiding this comment.
다른 패키지에 둘 이유가 없다고 생각해서 기존의 model 패키지에 합병했습니다!
코드 전체적으로 Refactoring 진행하였습니다.
|
sosow0212
left a comment
There was a problem hiding this comment.
이번 단계는 여기서 마무리하겠습니다!
변수명과 기본적인 자바에 대해서 리뷰를 했는데, 리뷰 내용 확인만 해주시고 다음 미션부터 적용해주세요!
수고하셨습니다 👍
| public int multipleNumbers(){ | ||
| return num1 * num2; | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
scanner.close()는 resource를 풀어주는 거라 다른 결이긴 합니다!
해당 링크 참고해보시면 좋을 것 같아요!
| } | ||
| return sum(listToInt(splitInput(input))); | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
보내주신 내용 확인해서 파일마다 끝에 한 줄 비워두는 방식으로 수정했습니다!
|
|
||
| public class InputView { | ||
|
|
||
| private Scanner scanner; |
There was a problem hiding this comment.
private,
private final,
private static final,
private static
각각 차이는 무엇일까요?
There was a problem hiding this comment.
private는 해당 클래스 내부에서만 접근 가능하게 만들어주는 접근 제어자 입니다.
private final은 한 번 값이 설정되면 그 값이 고정되며 인스턴스 별로 각기 다른 값을 가질 수 있습니다.
그리고 private에 의해 해당 클래스 내부에서만 접근 가능합니다.
private static final은 모든 인스턴스가 사용하는 고정된 값을 할당할 때 사용합니다. 주로 상수 설정에 사용합니다.
private static은 객체 생성 없이 사용 가능한 필드나 메서드들을 생성하고 싶을 때 사용합니다.
클래스의 모든 인스턴스가 접근 가능하지만 private에 의해 해당 클래스 내부에서만 접근 가능합니다.
위와 같이 이해하고 있는데 잘못된 부분이 있을까요?
| while (scanner.hasNextLine()) { | ||
| return scanner.nextLine(); | ||
| } | ||
| return null; |
There was a problem hiding this comment.
return scanner.next(); 이렇게 해도 될 것 같아요!
There was a problem hiding this comment.
EOF를 잘못 이해하고 나름대로 resource를 풀어주려고 작성했습니다.
보내주신 내용 확인하고 수정 완료했습니다!
| private static final int EXPECT_VALUE = 3; | ||
| private Calculator calculator; |
There was a problem hiding this comment.
| private static final int EXPECT_VALUE = 3; | |
| private Calculator calculator; | |
| private static final int EXPECT_VALUE = 3; | |
| private Calculator calculator; |
| assertThat(EXPECT_VALUE_ZERO).isEqualTo(calculator.add(null)); | ||
| assertThat(EXPECT_VALUE_ZERO).isEqualTo(calculator.add("")); |
There was a problem hiding this comment.
지금은 위에 테스트 메서드가 실패하면 아래는 작동하지 않아서 여러 값을 테스트한다면 softly로 적용하는 것이 좋을 것 같습니다!
2차 Code Refactoring 진행하였습니다.
Refactoring 과정에서 배운 내용
|
초간단 계산기와 문자열 계산기 구현해보았습니다.
테스트 코드를 처음 공부해보는데 덕분에 좋은 공부했습니다. 감사합니다!