-
Notifications
You must be signed in to change notification settings - Fork 155
[4기 - 한희나] 1~2주차 과제 : 계산기 미션 제출합니다. #158
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
Open
heenahan
wants to merge
34
commits into
prgrms-be-devcourse:heenahan
Choose a base branch
from
heenahan:main
base: heenahan
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
823468f
init : 프로젝트 초기화
heenahan 9f99b95
feat : 중위 표기식을 후위 표기식으로 변환해서 계산
heenahan c78db4c
test : 사칙 연산 테스트
heenahan 4e840f1
test : 후위표기식 변환 후 계산 테스트
heenahan 27c0031
feat : 연산 결과 맵에 저장
heenahan bb2ba06
feat : 문자열 연산을 리스트 연산으로 변환
heenahan 104c54b
test : 저장소, 문자열 연산을 리스트 연산으로 변환 테스트
heenahan 91ae6e6
chore : 출력문 삭제
heenahan dd89153
feat : 유효하지 않은 입력값은 예외 던짐
heenahan 73a262d
feat : DB은 불변해야 하므로 final
heenahan e4a7702
test : 잘못된 수식이 입력되는 예외 테스트
heenahan 88acf06
feat : 입력과 출력 추가
heenahan 46aed93
feat : 컨트롤러 추가
heenahan ef913ec
docs : gradle 파일 추가
heenahan 679a107
refactor : 우선순위 enum에서 관리 및 enum 안에서 사칙 연산 수행
heenahan b00a4fb
refactor : 자료구조 변경 stack -> deque
heenahan 9a70dfa
feat : custom exception 만듦
heenahan 0abe54e
refactor : Operator를 ParameterizedTest를 사용해 여러 개를 테스트 및 Calculator 메서…
heenahan fa9691b
feat : 동일한 수식도 저장 및 시간 순으로 정렬한 리스트 반환
heenahan 91ee3a9
feat : 자주 사용되는 정규식 패턴 미리 컴파일 후 사용
heenahan a8161ac
feat : 메뉴 enum에서 관리
heenahan 6b41677
feat : 서비스 레이어로 분리
heenahan f0aff99
refactor : 컨트롤러 레이어 리팩토링
heenahan 5e74365
refactor : 애플리케이션 클래스 이름 변경
heenahan 752d38d
chore : import문 정리
heenahan d2e0f24
refactor : 후위 표현식 변환과 계산 분리
heenahan 26995f4
refactor : Formula가 스스로 계산하도록 변경
heenahan 8984cd5
feat : 저장소 List로 자료구조 변경
heenahan 6ce753c
refactor : 저장과 계산 테스트 코드 변경
heenahan 3a2acbf
refactor : 메뉴 번호 String으로 변경
heenahan 8ec3a90
refactor : 서비스 레이어 리팩토링
heenahan d59e1c0
refactor : 컨트롤러 레이어 리팩토링
heenahan b813f7c
fix : 마이너스 부호 입력 시 유효하지 않는 입력 예외 발생
heenahan f781b5f
refactor :인자로 Formula를 받음
heenahan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,218 @@ | ||
| # Ignore Gradle project-specific cache directory | ||
| .gradle | ||
|
|
||
| # Ignore Gradle build output directory | ||
| build | ||
| ### Java template | ||
| # Compiled class file | ||
| *.class | ||
|
|
||
| # Log file | ||
| *.log | ||
|
|
||
| # BlueJ files | ||
| *.ctxt | ||
|
|
||
| # Mobile Tools for Java (J2ME) | ||
| .mtj.tmp/ | ||
|
|
||
| # Package Files # | ||
| *.jar | ||
| *.war | ||
| *.nar | ||
| *.ear | ||
| *.zip | ||
| *.tar.gz | ||
| *.rar | ||
|
|
||
| # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
| hs_err_pid* | ||
|
|
||
| ### JetBrains template | ||
| # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider | ||
| # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 | ||
|
|
||
| # User-specific stuff | ||
| .idea/**/workspace.xml | ||
| .idea/**/tasks.xml | ||
| .idea/**/usage.statistics.xml | ||
| .idea/**/dictionaries | ||
| .idea/**/shelf | ||
|
|
||
| # Generated files | ||
| .idea/**/contentModel.xml | ||
|
|
||
| # Sensitive or high-churn files | ||
| .idea/**/dataSources/ | ||
| .idea/**/dataSources.ids | ||
| .idea/**/dataSources.local.xml | ||
| .idea/**/sqlDataSources.xml | ||
| .idea/**/dynamic.xml | ||
| .idea/**/uiDesigner.xml | ||
| .idea/**/dbnavigator.xml | ||
|
|
||
| # Gradle | ||
| .idea/**/gradle.xml | ||
| .idea/**/libraries | ||
|
|
||
| # Gradle and Maven with auto-import | ||
| # When using Gradle or Maven with auto-import, you should exclude module files, | ||
| # since they will be recreated, and may cause churn. Uncomment if using | ||
| # auto-import. | ||
| # .idea/artifacts | ||
| # .idea/compiler.xml | ||
| # .idea/jarRepositories.xml | ||
| # .idea/modules.xml | ||
| # .idea/*.iml | ||
| # .idea/modules | ||
| # *.iml | ||
| # *.ipr | ||
|
|
||
| # CMake | ||
| cmake-build-*/ | ||
|
|
||
| # Mongo Explorer plugin | ||
| .idea/**/mongoSettings.xml | ||
|
|
||
| # File-based project format | ||
| *.iws | ||
|
|
||
| # IntelliJ | ||
| out/ | ||
|
|
||
| # mpeltonen/sbt-idea plugin | ||
| .idea_modules/ | ||
|
|
||
| # JIRA plugin | ||
| atlassian-ide-plugin.xml | ||
|
|
||
| # Cursive Clojure plugin | ||
| .idea/replstate.xml | ||
|
|
||
| # Crashlytics plugin (for Android Studio and IntelliJ) | ||
| com_crashlytics_export_strings.xml | ||
| crashlytics.properties | ||
| crashlytics-build.properties | ||
| fabric.properties | ||
|
|
||
| # Editor-based Rest Client | ||
| .idea/httpRequests | ||
|
|
||
| # Android studio 3.1+ serialized cache file | ||
| .idea/caches/build_file_checksums.ser | ||
|
|
||
| ### Java template | ||
| # Compiled class file | ||
| *.class | ||
|
|
||
| # Log file | ||
| *.log | ||
|
|
||
| # BlueJ files | ||
| *.ctxt | ||
|
|
||
| # Mobile Tools for Java (J2ME) | ||
| .mtj.tmp/ | ||
|
|
||
| # Package Files # | ||
| *.jar | ||
| *.war | ||
| *.nar | ||
| *.ear | ||
| *.zip | ||
| *.tar.gz | ||
| *.rar | ||
|
|
||
| # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
| hs_err_pid* | ||
|
|
||
| ### JetBrains template | ||
| # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider | ||
| # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 | ||
|
|
||
| # User-specific stuff | ||
| .idea/**/workspace.xml | ||
| .idea/**/tasks.xml | ||
| .idea/**/usage.statistics.xml | ||
| .idea/**/dictionaries | ||
| .idea/**/shelf | ||
|
|
||
| # Generated files | ||
| .idea/**/contentModel.xml | ||
|
|
||
| # Sensitive or high-churn files | ||
| .idea/**/dataSources/ | ||
| .idea/**/dataSources.ids | ||
| .idea/**/dataSources.local.xml | ||
| .idea/**/sqlDataSources.xml | ||
| .idea/**/dynamic.xml | ||
| .idea/**/uiDesigner.xml | ||
| .idea/**/dbnavigator.xml | ||
|
|
||
| # Gradle | ||
| .idea/**/gradle.xml | ||
| .idea/**/libraries | ||
|
|
||
| # Gradle and Maven with auto-import | ||
| # When using Gradle or Maven with auto-import, you should exclude module files, | ||
| # since they will be recreated, and may cause churn. Uncomment if using | ||
| # auto-import. | ||
| # .idea/artifacts | ||
| # .idea/compiler.xml | ||
| # .idea/jarRepositories.xml | ||
| # .idea/modules.xml | ||
| # .idea/*.iml | ||
| # .idea/modules | ||
| # *.iml | ||
| # *.ipr | ||
|
|
||
| # CMake | ||
| cmake-build-*/ | ||
|
|
||
| # Mongo Explorer plugin | ||
| .idea/**/mongoSettings.xml | ||
|
|
||
| # File-based project format | ||
| *.iws | ||
|
|
||
| # IntelliJ | ||
| out/ | ||
|
|
||
| # mpeltonen/sbt-idea plugin | ||
| .idea_modules/ | ||
|
|
||
| # JIRA plugin | ||
| atlassian-ide-plugin.xml | ||
|
|
||
| # Cursive Clojure plugin | ||
| .idea/replstate.xml | ||
|
|
||
| # Crashlytics plugin (for Android Studio and IntelliJ) | ||
| com_crashlytics_export_strings.xml | ||
| crashlytics.properties | ||
| crashlytics-build.properties | ||
| fabric.properties | ||
|
|
||
| # Editor-based Rest Client | ||
| .idea/httpRequests | ||
|
|
||
| # Android studio 3.1+ serialized cache file | ||
| .idea/caches/build_file_checksums.ser | ||
|
|
||
| ### Gradle template | ||
| .gradle | ||
| **/build/ | ||
| !src/**/build/ | ||
|
|
||
| # Ignore Gradle GUI config | ||
| gradle-app.setting | ||
|
|
||
| # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) | ||
| !gradle-wrapper.jar | ||
|
|
||
| # Cache of project | ||
| .gradletasknamecache | ||
|
|
||
| # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 | ||
| # gradle/wrapper/gradle-wrapper.properties | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * This file was generated by the Gradle 'init' task. | ||
| * | ||
| * This generated file contains a sample Java application project to get you started. | ||
| * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle | ||
| * User Manual available at https://docs.gradle.org/8.1.1/userguide/building_java_projects.html | ||
| * This project uses @Incubating APIs which are subject to change. | ||
| */ | ||
|
|
||
| plugins { | ||
| // Apply the application plugin to add support for building a CLI application in Java. | ||
| id 'application' | ||
| } | ||
|
|
||
| repositories { | ||
| // Use Maven Central for resolving dependencies. | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| // This dependency is used by the application. | ||
| implementation 'com.google.guava:guava:31.1-jre' | ||
|
|
||
| // https://mvnrepository.com/artifact/org.assertj/assertj-core | ||
| testImplementation 'org.assertj:assertj-core:3.24.2' | ||
| } | ||
|
|
||
| testing { | ||
| suites { | ||
| // Configure the built-in test suite | ||
| test { | ||
| // Use JUnit Jupiter test framework | ||
| useJUnitJupiter('5.9.1') | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Apply a specific Java toolchain to ease working on different environments. | ||
| java { | ||
| toolchain { | ||
| languageVersion = JavaLanguageVersion.of(11) | ||
| } | ||
| } | ||
|
|
||
| application { | ||
| // Define the main class for the application. | ||
| mainClass = 'com.programmers.App' | ||
| } |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/programmers/CalculatorApplication.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /* | ||
| * This Java source file was generated by the Gradle 'init' task. | ||
| */ | ||
| package com.programmers; | ||
|
|
||
| import com.programmers.controller.CalculatorController; | ||
|
|
||
| public class CalculatorApplication { | ||
|
|
||
| public static void main(String[] args) { | ||
| CalculatorController calculatorController = new CalculatorController(); | ||
| calculatorController.run(); | ||
| } | ||
|
|
||
| } |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/programmers/calculator/Calculator.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.programmers.calculator; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Calculator { | ||
|
|
||
| private final PostfixConversion postfixConversion; | ||
| private final PostfixCalculator postfixCalculator; | ||
|
|
||
| public Calculator() { | ||
| postfixConversion = new PostfixConversion(); | ||
| postfixCalculator = new PostfixCalculator(); | ||
| } | ||
|
|
||
| public Integer calculate(Formula formula) { | ||
| List<String> postfix = postfixConversion.changeInfixToPostfix(formula.getInfixListFormula()); | ||
| return postfixCalculator.calculatePostfix(postfix); | ||
| } | ||
|
|
||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package com.programmers.calculator; | ||
|
|
||
| import com.programmers.exception.InvalidFormulaException; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.regex.Pattern; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class Formula { | ||
|
|
||
| private static final Pattern FORMULA_REGEX = Pattern.compile("([0-9] [+|\\-|*|/] )+[0-9]"); | ||
| private static final String EQUAL = " = "; | ||
|
|
||
| private final Calculator calculator; | ||
|
|
||
| private String formula; | ||
| private Integer result; | ||
|
|
||
| public Formula(String formula) { | ||
| isValid(formula); | ||
| this.formula = formula; | ||
| this.calculator = new Calculator(); | ||
| } | ||
|
|
||
| public List<String> getInfixListFormula() { | ||
| return Arrays.stream(formula.split(" ")) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public void isValid(String formula) { | ||
| if (!FORMULA_REGEX.matcher(formula).matches()) throw new InvalidFormulaException("유효하지 않은 수식 입력입니다."); | ||
| } | ||
|
|
||
| public Integer calcualteFormula() { | ||
| result = calculator.calculate(this); | ||
| return result; | ||
| } | ||
|
|
||
| public String toString() { | ||
| return formula + EQUAL + result; | ||
| } | ||
|
|
||
| } | ||
38 changes: 38 additions & 0 deletions
38
app/src/main/java/com/programmers/calculator/PostfixCalculator.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.programmers.calculator; | ||
|
|
||
| import com.programmers.util.Operator; | ||
|
|
||
| import java.util.ArrayDeque; | ||
| import java.util.Deque; | ||
| import java.util.List; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class PostfixCalculator { | ||
|
|
||
| private static final Pattern NUMBER = Pattern.compile("\\d+"); | ||
|
|
||
| public Integer calculatePostfix(List<String> postfix) { | ||
| Deque<Integer> deque = new ArrayDeque<>(); | ||
|
|
||
| postfix.stream() | ||
| .forEach(s -> { calculatePostfixWithDeque(s, deque); }); | ||
|
|
||
| return deque.pollLast(); | ||
| } | ||
|
|
||
| private void calculatePostfixWithDeque(String s, Deque<Integer> deque) { | ||
| if (NUMBER.matcher(s).matches()) { | ||
| deque.addLast(Integer.parseInt(s)); | ||
| return; | ||
| } | ||
| // 연산자 일 경우 | ||
| Integer op1 = deque.pollLast(); | ||
| Integer op2 = deque.pollLast(); | ||
|
|
||
| Operator calc = Operator.of(s); | ||
| Integer result = calc.calculateOperation(op2, op1); | ||
|
|
||
| deque.addLast(result); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
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.
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는 어떻게 보면 데이터만 가지고 있는 객체인듯 한데요.Calculator를 의존하신 이유가 있을까요??