diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000..9df9034ad
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,207 @@
+# Created by https://www.toptal.com/developers/gitignore/api/java,macos,intellij,gradle
+# Edit at https://www.toptal.com/developers/gitignore?templates=java,macos,intellij,gradle
+
+### Intellij ###
+# 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
+
+# AWS User-specific
+.idea/**/aws.xml
+
+# 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
+
+# SonarLint plugin
+.idea/sonarlint/
+
+# 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
+
+### Intellij Patch ###
+# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
+
+# *.iml
+# modules.xml
+# .idea/misc.xml
+# *.ipr
+
+# Sonarlint plugin
+# https://plugins.jetbrains.com/plugin/7973-sonarlint
+.idea/**/sonarlint/
+
+# SonarQube Plugin
+# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
+.idea/**/sonarIssues.xml
+
+# Markdown Navigator plugin
+# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
+.idea/**/markdown-navigator.xml
+.idea/**/markdown-navigator-enh.xml
+.idea/**/markdown-navigator/
+
+# Cache file creation bug
+# See https://youtrack.jetbrains.com/issue/JBR-2257
+.idea/$CACHE_FILE$
+
+# CodeStream plugin
+# https://plugins.jetbrains.com/plugin/12206-codestream
+.idea/codestream.xml
+
+# Azure Toolkit for IntelliJ plugin
+# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
+.idea/**/azureSettings.xml
+
+### Java ###
+# 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*
+replay_pid*
+
+### macOS ###
+# General
+.DS_Store
+.AppleDouble
+.LSOverride
+
+# Icon must end with two \r
+Icon
+
+
+# Thumbnails
+._*
+
+# Files that might appear in the root of a volume
+.DocumentRevisions-V100
+.fseventsd
+.Spotlight-V100
+.TemporaryItems
+.Trashes
+.VolumeIcon.icns
+.com.apple.timemachine.donotpresent
+
+# Directories potentially created on remote AFP share
+.AppleDB
+.AppleDesktop
+Network Trash Folder
+Temporary Items
+.apdisk
+
+### macOS Patch ###
+# iCloud generated files
+*.icloud
+
+### Gradle ###
+.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
+
+# Avoid ignore Gradle wrappper properties
+!gradle-wrapper.properties
+
+# Cache of project
+.gradletasknamecache
+
+# Eclipse Gradle plugin generated files
+# Eclipse Core
+.project
+# JDT-specific (Eclipse Java Development Tools)
+.classpath
+
+### Gradle Patch ###
+# Java heap dump
+*.hprof
+
+.idea
+.gradle
+
+
+# End of https://www.toptal.com/developers/gitignore/api/java,macos,intellij,gradle
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 000000000..22bad42ac
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,26 @@
+plugins{
+ id 'java'
+}
+
+group 'org.example'
+version '1.0-SNAPSHOT'
+
+repositories {
+ mavenCentral()
+}
+sourceSets {
+ main {
+ java {
+ srcDirs = ['src']
+ }
+ }
+}
+dependencies {
+ implementation 'org.junit.jupiter:junit-jupiter:5.9.1'
+ testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
+ testImplementation 'org.junit.jupiter:junit-jupiter-params:5.4.2'
+}
+
+tasks.named('test') {
+ useJUnitPlatform()
+}
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..41d9927a4
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..41dfb8790
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,5 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
new file mode 100755
index 000000000..1b6c78733
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,234 @@
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+##############################################################################
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# within the Gradle project.
+#
+# You can find Gradle at https://github.com/gradle/gradle/.
+#
+##############################################################################
+
+# Attempt to set APP_HOME
+
+# Resolve links: $0 may be a link
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
+done
+
+APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
+
+APP_NAME="Gradle"
+APP_BASE_NAME=${0##*/}
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD=maximum
+
+warn () {
+ echo "$*"
+} >&2
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+} >&2
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD=$JAVA_HOME/jre/sh/java
+ else
+ JAVACMD=$JAVA_HOME/bin/java
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD=java
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
+ esac
+fi
+
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
+
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
+ fi
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
+ done
+fi
+
+# Collect all arguments for the java command;
+# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
+# shell script including quotes and variable substitutions, so put them in
+# double quotes to make sure that they get re-expanded; and
+# * put everything else in single quotes, so that it's not re-expanded.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ org.gradle.wrapper.GradleWrapperMain \
+ "$@"
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 000000000..ac1b06f93
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,89 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/java-calculator.iml b/java-calculator.iml
new file mode 100644
index 000000000..8021953ed
--- /dev/null
+++ b/java-calculator.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/CalculateProgram.java b/src/main/java/CalculateProgram.java
new file mode 100644
index 000000000..a54358ed5
--- /dev/null
+++ b/src/main/java/CalculateProgram.java
@@ -0,0 +1,15 @@
+package main.java;
+
+import main.java.controller.Controller;
+import main.java.repository.MapHistoryRepository;
+import main.java.service.Calculator;
+import main.java.view.ConsoleInput;
+import main.java.view.ConsoleOutput;
+
+public class CalculateProgram {
+
+ public static void main(String[] args) {
+ new Controller(new ConsoleInput(), new ConsoleOutput(), new Calculator(), new MapHistoryRepository()).run();
+ }
+
+}
diff --git a/src/main/java/controller/Controller.java b/src/main/java/controller/Controller.java
new file mode 100644
index 000000000..cb71d7088
--- /dev/null
+++ b/src/main/java/controller/Controller.java
@@ -0,0 +1,65 @@
+package main.java.controller;
+
+import main.java.domain.Command;
+import main.java.domain.History;
+import main.java.domain.Menu;
+import main.java.repository.HistoryRepository;
+import main.java.service.Calculator;
+import main.java.view.Input;
+import main.java.view.Output;
+
+import static main.java.view.ConsoleInput.*;
+
+
+public class Controller {
+
+ private final Input input;
+ private final Output output;
+ private final Calculator calculator;
+ private final HistoryRepository repository;
+
+ public Controller(Input input, Output output, Calculator calculator, HistoryRepository repository) {
+ this.input = input;
+ this.output = output;
+ this.calculator = calculator;
+ this.repository = repository;
+ }
+
+ public void run() {
+
+ while(true) {
+ try {
+ output.printMenu(Menu.values());
+ // menu 객체로 만듦.
+ Menu menu = input.getMenuInput();
+
+ switch (menu.getMenuNum()) {
+ case SHOWMENU:
+ output.showHistory(repository.getAllHistoryToList());
+ break;
+
+ case CALCULATEMENU:
+ Command command = new Command(input.getLineAndParse());
+ int result = calculator.calculate(command);
+
+ // output에서 DTO
+ output.printResult(result);
+ History history = new History(command.getCommandArr(), result);
+ repository.saveHistory(history);
+ break;
+
+ case EXITMENU:
+ output.exitProgram();
+ scannerClose();
+ return;
+ }
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+}
diff --git a/src/main/java/domain/Command.java b/src/main/java/domain/Command.java
new file mode 100644
index 000000000..fe0bb4ad3
--- /dev/null
+++ b/src/main/java/domain/Command.java
@@ -0,0 +1,47 @@
+package main.java.domain;
+
+import main.java.service.Operator;
+
+public class Command {
+
+ private String[] commandArr;
+ private int[] numberArr;
+ private Operator[] optArr;
+ private int optCount;
+
+ public Command(String[] commandArr) {
+ this.commandArr = commandArr;
+ this.optCount = commandArr.length / 2;
+ this.numberArr = new int[optCount + 1];
+ this.optArr = new Operator[optCount];
+
+ parseComamand();
+ }
+
+ public String[] getCommandArr() {
+ return commandArr;
+ }
+
+ public int[] getNumberArr() {
+ return numberArr;
+ }
+
+ public Operator[] getOptArr() {
+ return optArr;
+ }
+
+ public int getOptCount() {
+ return optCount;
+ }
+
+ public void parseComamand() {
+ for(int i = 0; i < commandArr.length; i++) {
+ if(i % 2 == 0) {
+ numberArr[i / 2] = Integer.parseInt(commandArr[i]);
+ continue;
+ }
+ optArr[i / 2] = Operator.stringToOperator(commandArr[i]);
+ }
+ }
+
+}
diff --git a/src/main/java/domain/History.java b/src/main/java/domain/History.java
new file mode 100644
index 000000000..875618458
--- /dev/null
+++ b/src/main/java/domain/History.java
@@ -0,0 +1,13 @@
+package main.java.domain;
+
+public class History {
+ private String history;
+
+ public History(String[] commandArr, int result) {
+ this.history = String.join(" ", commandArr) + " = " + result;
+ }
+
+ public String getHistory() {
+ return history;
+ }
+}
diff --git a/src/main/java/domain/Menu.java b/src/main/java/domain/Menu.java
new file mode 100644
index 000000000..5748d49bd
--- /dev/null
+++ b/src/main/java/domain/Menu.java
@@ -0,0 +1,40 @@
+package main.java.domain;
+
+import java.util.Arrays;
+
+// 메뉴도 하나의 Data 단위.
+public enum Menu {
+ SELECT(-1, "선택 : "),
+ EXIT(0, "종료"),
+ SHOW(1, "조회"),
+ CALCULATE(2, "계산");
+
+ private final int menuNum;
+ private final String menuName;
+ public static final int menuCount = Menu.values().length - 1;
+
+ Menu(int menuNum, String menuName) {
+ this.menuNum = menuNum;
+ this.menuName = menuName;
+ }
+
+ public int getMenuNum() {
+ return menuNum;
+ }
+
+ public String getMenuName() {
+ return menuName;
+ }
+
+ public static Menu getMenu(int menu) {
+ return Arrays.stream(values())
+ .filter(value -> value.menuNum==(menu))
+ .findAny()
+ .orElse(null);
+ }
+
+ @Override
+ public String toString() {
+ return menuNum + ". " + menuName;
+ }
+}
diff --git a/src/main/java/repository/HistoryRepository.java b/src/main/java/repository/HistoryRepository.java
new file mode 100644
index 000000000..981d47863
--- /dev/null
+++ b/src/main/java/repository/HistoryRepository.java
@@ -0,0 +1,12 @@
+package main.java.repository;
+
+import main.java.domain.History;
+
+import java.util.List;
+
+public interface HistoryRepository {
+
+ void saveHistory(History history);
+ List getAllHistoryToList();
+ boolean isEmpty();
+}
diff --git a/src/main/java/repository/MapHistoryRepository.java b/src/main/java/repository/MapHistoryRepository.java
new file mode 100644
index 000000000..8bb650ad6
--- /dev/null
+++ b/src/main/java/repository/MapHistoryRepository.java
@@ -0,0 +1,31 @@
+package main.java.repository;
+
+import main.java.domain.History;
+
+import java.util.*;
+
+public class MapHistoryRepository implements HistoryRepository {
+
+ private int historyCount;
+ private Map MapHistoryRepository;
+ public MapHistoryRepository() {
+ MapHistoryRepository = new LinkedHashMap<>();
+ historyCount = 0;
+ }
+
+ @Override
+ public void saveHistory(History history) {
+ MapHistoryRepository.put(historyCount, history);
+ historyCount++;
+ }
+
+ @Override
+ public List getAllHistoryToList() {
+ return new ArrayList<>(MapHistoryRepository.values());
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return MapHistoryRepository.isEmpty();
+ }
+}
diff --git a/src/main/java/service/Calculator.java b/src/main/java/service/Calculator.java
new file mode 100644
index 000000000..0779c49e9
--- /dev/null
+++ b/src/main/java/service/Calculator.java
@@ -0,0 +1,54 @@
+package main.java.service;
+
+import main.java.domain.Command;
+
+import java.util.Stack;
+
+public class Calculator {
+
+ private Operator PM;
+ private Operator MD;
+
+ public Calculator() {}
+
+ public int calculate(Command command) {
+ PM = Operator.PLUS;
+ MD = Operator.MULTIPLY;
+
+ int result = 0;
+
+ int[] numberArr = command.getNumberArr();
+ Operator[] optArr = command.getOptArr();
+
+ Stack stack = new Stack<>();
+
+ for(int i = 0; i < command.getOptCount(); i++) {
+ // nums
+ calculateAndPush(numberArr[i], stack);
+
+ // opts
+ if(optArr[i].isPlusOrMinus()) {
+ result = PM.calculateOpt(result, stack.peek());
+ PM = optArr[i];
+ stack.pop();
+ continue;
+ }
+ MD = optArr[i];
+ }
+
+ calculateAndPush(numberArr[command.getOptCount()], stack);
+ // 마지막 command의 숫자까지 처리.
+ result = PM.calculateOpt(result, stack.peek());
+ return result;
+ }
+
+ private void calculateAndPush(int number, Stack stack) {
+ if(stack.isEmpty()) {
+ stack.push(number);
+ return;
+ }
+ int top = stack.peek();
+ stack.pop();
+ stack.push(MD.calculateOpt(top, number));
+ }
+}
diff --git a/src/main/java/service/Operator.java b/src/main/java/service/Operator.java
new file mode 100644
index 000000000..55330a059
--- /dev/null
+++ b/src/main/java/service/Operator.java
@@ -0,0 +1,59 @@
+package main.java.service;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.function.BiFunction;
+import java.util.stream.Collectors;
+
+public enum Operator {
+ PLUS("+", (a, b) -> (a + b)),
+ MINUS("-", (a, b) -> (a - b)),
+ MULTIPLY("*", (a, b) -> (a * b)),
+ DIVIDE("/", (a, b) -> (a / b));
+
+ public final String optName;
+ private final BiFunction biFunction;
+
+ Operator(String optName, BiFunction biFunction) {
+ this.optName = optName;
+ this.biFunction = biFunction;
+ }
+
+ public String getOptName() {
+ return optName;
+ }
+
+ public boolean isPlusOrMinus() {
+ if(this == PLUS || this == MINUS)
+ return true;
+ return false;
+ }
+
+ public Integer calculateOpt(Integer a, Integer b) {
+ return this.biFunction.apply(a, b);
+ }
+
+ // for checking valid operator input.
+ private static List toStringArray(Operator[] operators) {
+ return Arrays.stream(operators)
+ .map(Operator::getOptName)
+ .collect(Collectors.toList());
+ }
+
+ public static boolean isValidOperator(String comp) {
+ // Operator 의 optName(+ - / =) 에 해당하는 optNames List를 만들고
+ // 인자인 comp가 optNames안에 들어있는지 검사.
+ List optNames = toStringArray(Operator.values());
+ if(optNames.contains(comp))
+ return true;
+ return false;
+ }
+
+ public static Operator stringToOperator(String operator) {
+ return Arrays.stream(values())
+ .filter(value -> value.optName.equals(operator))
+ .findAny()
+ .orElse(null);
+ }
+}
diff --git a/src/main/java/view/ConsoleInput.java b/src/main/java/view/ConsoleInput.java
new file mode 100644
index 000000000..71629053c
--- /dev/null
+++ b/src/main/java/view/ConsoleInput.java
@@ -0,0 +1,70 @@
+package main.java.view;
+
+import main.java.domain.Menu;
+import org.junit.jupiter.api.Test;
+
+import java.util.Scanner;
+
+import static main.java.domain.Menu.getMenu;
+import static main.java.service.Operator.isValidOperator;
+import static main.java.view.ConsoleOutput.printError;
+
+
+public class ConsoleInput implements Input{
+
+ private static final Scanner scanner = new Scanner(System.in);
+ private static final String DELIMINATOR = " ";
+ public static final int SHOWMENU = 1;
+ public static final int CALCULATEMENU = 2;
+ public static final int EXITMENU = 0;
+
+ public Menu getMenuInput() {
+ String line = scanner.nextLine();
+ String[] lineArr = line.split(DELIMINATOR);
+ String menuCandidate = lineArr[0];
+ if (lineArr.length >= 2 || !isValidNumber(menuCandidate)
+ || Integer.parseInt(menuCandidate) >= Menu.menuCount
+ || Integer.parseInt(menuCandidate) < 0) {
+ throw new IllegalArgumentException(printError("MENU"));
+ }
+ return getMenu(Integer.parseInt(menuCandidate));
+ }
+
+ public String[] getLineAndParse() {
+ String[] commandArr = scanner.nextLine().split(DELIMINATOR);
+ if(!isValidCommand(commandArr))
+ throw new IllegalArgumentException(printError("COMMAND"));
+ return commandArr;
+ }
+
+ public static void scannerClose() {
+ scanner.close();
+ }
+
+ // 각각 숫자 , 연산자에 대해 맞는 command인지 검사.
+ public boolean isValidCommand(String[] commandArr) {
+ String commandEntity;
+ for(int i = 0; i < commandArr.length; i++) {
+ commandEntity = commandArr[i];
+ if(i % 2 == 0) {
+ if(!isValidNumber(commandEntity))
+ return false;
+ }
+ else {
+ if(!isValidOperator(commandEntity))
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static boolean isValidNumber(String commandEntity) {
+ for(int i = 0; i < commandEntity.length(); i++) {
+ if(!Character.isDigit(commandEntity.charAt(i)))
+ return false;
+ }
+
+ return true;
+ }
+
+}
diff --git a/src/main/java/view/ConsoleOutput.java b/src/main/java/view/ConsoleOutput.java
new file mode 100644
index 000000000..6ddbe54f4
--- /dev/null
+++ b/src/main/java/view/ConsoleOutput.java
@@ -0,0 +1,47 @@
+package main.java.view;
+
+import main.java.domain.History;
+import main.java.domain.Menu;
+
+import java.util.List;
+
+public class ConsoleOutput implements Output{
+
+ private static final String EXIT_MESSAGE = "EXIT calculate ..";
+ public static final String EMPTY_MESSAGE = "Repository is EMPTY!!";
+
+ public static String printError(String error) {
+ return "WRONG " + error + " ! PLEASE RE-TYPE!!";
+ }
+
+ // 자원정리의 주체가 output이 돼도 되나?
+ @Override
+ public void exitProgram() {
+ System.out.println(EXIT_MESSAGE);
+ }
+
+ @Override
+ public void printResult(int result) {
+ System.out.println(result);
+ }
+
+ @Override
+ public void showHistory(List historyList) {
+ if(historyList.isEmpty()) {
+ System.out.println(EMPTY_MESSAGE);
+ return;
+ }
+ for(History historyEntity : historyList) {
+ System.out.println(historyEntity.getHistory());
+ }
+ }
+
+ @Override
+ public void printMenu(Menu[] menus) {
+ for(int i = 1; i < menus.length; i++) {
+ System.out.println(menus[i]);
+ }
+ System.out.println(menus[0].getMenuName());
+ }
+
+}
diff --git a/src/main/java/view/Input.java b/src/main/java/view/Input.java
new file mode 100644
index 000000000..6ee9b97af
--- /dev/null
+++ b/src/main/java/view/Input.java
@@ -0,0 +1,9 @@
+package main.java.view;
+
+import main.java.domain.Menu;
+
+public interface Input {
+ Menu getMenuInput();
+
+ String[] getLineAndParse();
+}
diff --git a/src/main/java/view/Output.java b/src/main/java/view/Output.java
new file mode 100644
index 000000000..ffe6fdba0
--- /dev/null
+++ b/src/main/java/view/Output.java
@@ -0,0 +1,16 @@
+package main.java.view;
+
+import main.java.domain.History;
+import main.java.domain.Menu;
+
+import java.util.List;
+
+public interface Output {
+
+ void exitProgram();
+ void showHistory(List historyList);
+
+ void printMenu(Menu[] menus);
+ void printResult(int result);
+
+}
diff --git a/src/src.iml b/src/src.iml
new file mode 100644
index 000000000..6e2c7755a
--- /dev/null
+++ b/src/src.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/CalculatorTest.java b/src/test/CalculatorTest.java
new file mode 100644
index 000000000..6ac6f327f
--- /dev/null
+++ b/src/test/CalculatorTest.java
@@ -0,0 +1,30 @@
+import main.java.domain.Command;
+import main.java.service.Calculator;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.DisplayName;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class CalculatorTest {
+
+ static Calculator calculator;
+ @BeforeAll
+ public static void setting() {
+ calculator = new Calculator();
+ }
+
+ @DisplayName("calculate함수는 띄어쓰기로 파싱된 input을 계산하는 함수.")
+ @ParameterizedTest
+ @CsvSource({"5 * 2 + 64 / 32 - 7, 5",
+ "15 / 5 * 2 + 8 / 2, 10",
+ "2 + 12 / 6 - 3 * 7, -17",
+ "7 - 25 * 3 + 20 / 10, -66"
+ })
+ // Test는 하나의 시나리오에 대해서만 검증하도록.
+ void calculateTest(String input, int expected) {
+ Command command = new Command(input.split(" "));
+ assertEquals(expected, calculator.calculate(command));
+ }
+}
diff --git a/src/test/CommandTest.java b/src/test/CommandTest.java
new file mode 100644
index 000000000..54baae888
--- /dev/null
+++ b/src/test/CommandTest.java
@@ -0,0 +1,46 @@
+import main.java.domain.Command;
+import main.java.service.Calculator;
+import main.java.service.Operator;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+
+public class CommandTest {
+
+ static Command command;
+ static int[] compNumArr;
+ static Operator[] compOptArr;
+ static Calculator calculator;
+
+ @BeforeAll
+ public static void setting() {
+ command = new Command(stringToArray("1 + 2 + 3"));
+ compNumArr = new int[] {1, 2, 3};
+ compOptArr = new Operator[] {Operator.PLUS, Operator.PLUS};
+ calculator = new Calculator();
+ }
+
+ @DisplayName("parseCommand는 인자로 들어온 String array를" +
+ "각각 정수와 연산자로 나눠주는 함수" +
+ "Command생성할때 이미 parsing완료한다.")
+ @Test
+ public void parseCommandTest() {
+ assertArrayEquals(compOptArr, command.getOptArr());
+ assertArrayEquals(compNumArr, command.getNumberArr());
+ }
+
+// @DisplayName("makeHistory는 인자로 들어온 result와 " +
+// "연산에 이용한 command를 합쳐서 String으로 리턴하는 함수")
+// @Test
+// public void makeHistoryTest() {
+// String expectedHistory = "1 + 2 + 3 = 6";
+// assertEquals(expectedHistory, command.makeHistory(calculator.calculate(command)));
+// }
+
+ public static String[] stringToArray(String input) {
+ return input.split(" ");
+ }
+}
diff --git a/src/test/MenuTest.java b/src/test/MenuTest.java
new file mode 100644
index 000000000..943204b42
--- /dev/null
+++ b/src/test/MenuTest.java
@@ -0,0 +1,14 @@
+import main.java.domain.Menu;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class MenuTest {
+
+ @DisplayName("선택 메뉴를 제외한, 화면에 출력될 메뉴의 갯수를 테스트.")
+ @Test
+ public void menuCountTest() {
+ assertEquals(3, Menu.menuCount);
+ }
+}
diff --git a/src/test/test.iml b/src/test/test.iml
new file mode 100644
index 000000000..7f4fe5fa8
--- /dev/null
+++ b/src/test/test.iml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file