diff --git a/README.md b/docs/README.md
similarity index 89%
rename from README.md
rename to docs/README.md
index 00410ae50..4d709d7db 100644
--- a/README.md
+++ b/docs/README.md
@@ -3,6 +3,39 @@
+## ๐พ ๊ธฐ๋ฅ ๋ชฉ๋ก `new`
+
+- ํ๋ก๊ทธ๋จ ์์
+ - ์ด๊ธฐ ์ ๋ณด ๋ฑ๋ก
+ - ๋ชฉ๋ก UI
+ - ๋ชฉ๋ก ๋ด ๋ฒํธ์ธ์ง ๊ฒ์ฆ
+- ์งํ์ฒ ์ญ ๊ด๋ จ ๊ธฐ๋ฅ
+ - ์ญ ์ด๋ฆ์ด 2์ ์ด์์ธ์ง ๊ฒ์ฆ
+ - ์ค๋ณต๋ ์ญ ์ด๋ฆ์ด ์๋์ง ๊ฒ์ฆ
+ - ์ญ ๋ฑ๋ก
+ - ์ญ ์ญ์
+ - `static` ์ญ ๋ชฉ๋ก ์กฐํ
+- ์งํ์ฒ ๋
ธ์ ๊ด๋ จ ๊ธฐ๋ฅ
+ - ๋
ธ์ ์ด๋ฆ์ด 2์ ์ด์์ธ์ง ๊ฒ์ฆ
+ - ์ค๋ณต๋ ๋
ธ์ ์ด๋ฆ์ด ์๋์ง ๊ฒ์ฆ
+ - ๋
ธ์ ๋ฑ๋ก
+ - ์ํ, ํํ ์ข
์ ์ญ ์กด์ฌ ์ฌ๋ถ ๊ฒ์ฆ
+ - ๋
ธ์ ์ญ์
+ - `static` ๋
ธ์ ๋ชฉ๋ก ์กฐํ
+- ์งํ์ฒ ๊ตฌ๊ฐ ๊ด๋ จ ๊ธฐ๋ฅ
+ - ๊ตฌ๊ฐ ๋ฑ๋ก
+ - ๋
ธ์ ์กด์ฌ ์ฌ๋ถ ๊ฒ์ฆ
+ - ์ญ ์กด์ฌ ์ฌ๋ถ ๊ฒ์ฆ
+ - ๋
ธ์ ๋ด ์ญ ์กด์ฌ ์ฌ๋ถ ๊ฒ์ฆ
+ - ์ํ, ํํ ์ข
์ ์ผ ๊ฒฝ์ฐ ๊ฐ๋ฅ
+ - ์ํํ ์ฌ๋ถ ํ์ธ ๋ฐ ๋ณ๊ฒฝ
+ - ๊ตฌ๊ฐ ์ญ์
+ - ๋
ธ์ ์กด์ฌ ์ฌ๋ถ ๊ฒ์ฆ
+ - ์ญ ์กด์ฌ ์ฌ๋ถ ๊ฒ์ฆ
+ - ๋
ธ์ ๋ด ์ญ 2๊ฐ ์ด๊ณผ์ธ์ง ๊ฒ์ฆ
+ - ์ํํ ์ฌ๋ถ ํ์ธ ๋ฐ ๋ณ๊ฒฝ
+- ๋
ธ์ ๋ ์กฐํ
+
## ๐ ๊ธฐ๋ฅ ์๊ตฌ์ฌํญ
### ์ด๊ธฐ ์ค์
@@ -19,7 +52,7 @@
- ์ ๋ถ๋น์ : ๊ฐ๋จ์ญ - ์์ฌ์ญ - ์์ฌ์๋ฏผ์์ฒ์ญ
```
-
+
### ์งํ์ฒ ์ญ ๊ด๋ จ ๊ธฐ๋ฅ
- ์งํ์ฒ ์ญ์ ๋ฑ๋กํ๊ณ ์ญ์ ํ ์ ์๋ค. (๋จ, ๋
ธ์ ์ ๋ฑ๋ก๋ ์ญ์ ์ญ์ ํ ์ ์๋ค)
@@ -41,14 +74,14 @@
- ์ญ๊ณผ ์ญ ์ฌ์ด์ ์๋ก์ด ์ญ์ด ์ถ๊ฐ ๋ ์ ์๋ค.
- ๋
ธ์ ์์ ๊ฐ๋๊ธธ์ ์๊ธธ ์ ์๋ค.
-
+
### ์งํ์ฒ ๊ตฌ๊ฐ ์ญ์ ๊ธฐ๋ฅ
- ๋
ธ์ ์ ๋ฑ๋ก๋ ์ญ์ ์ ๊ฑฐํ ์ ์๋ค.
- ์ข
์ ์ ์ ๊ฑฐํ ๊ฒฝ์ฐ ๋ค์ ์ญ์ด ์ข
์ ์ด ๋๋ค.
- ๋
ธ์ ์ ํฌํจ๋ ์ญ์ด ๋๊ฐ ์ดํ์ผ ๋๋ ์ญ์ ์ ๊ฑฐํ ์ ์๋ค.
-
+
### ์งํ์ฒ ๋
ธ์ ์ ๋ฑ๋ก๋ ์ญ ์กฐํ ๊ธฐ๋ฅ
- ๋
ธ์ ์ ์ํ ์ข
์ ๋ถํฐ ํํ ์ข
์ ๊น์ง ์ฐ๊ฒฐ๋ ์์๋๋ก ์ญ ๋ชฉ๋ก์ ์กฐํํ ์ ์๋ค.
diff --git a/src/main/java/subway/Application.java b/src/main/java/subway/Application.java
index 0bcf786cc..8597dc81f 100644
--- a/src/main/java/subway/Application.java
+++ b/src/main/java/subway/Application.java
@@ -1,10 +1,15 @@
package subway;
import java.util.Scanner;
+import subway.controller.MenuController;
+import subway.domain.service.LineService;
+import subway.domain.service.StationService;
public class Application {
public static void main(String[] args) {
final Scanner scanner = new Scanner(System.in);
- // TODO: ํ๋ก๊ทธ๋จ ๊ตฌํ
+ StationService.init();
+ LineService.init();
+ MenuController.runProgram(scanner);
}
}
diff --git a/src/main/java/subway/controller/LineController.java b/src/main/java/subway/controller/LineController.java
new file mode 100644
index 000000000..c915f0e74
--- /dev/null
+++ b/src/main/java/subway/controller/LineController.java
@@ -0,0 +1,61 @@
+package subway.controller;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+import subway.domain.Station;
+import subway.domain.service.LineService;
+import subway.domain.service.StationService;
+import subway.view.DetailView;
+import utils.Category;
+import utils.ScriptUtils;
+
+public class LineController {
+ public static final int ADD = 1;
+ public static final int DELETE = 2;
+ public static final int GET_LIST = 3;
+
+ public static DetailView lineView = new DetailView(Category.LINE);
+
+ private LineController() {}
+
+ public static void manageLine(Scanner scanner, int selection) {
+ String name = lineView.ask(scanner, selection);
+ if (name == null) {
+ return;
+ }
+ if (selection == DELETE) {
+ LineService.deleteLine(name);
+ return;
+ }
+ addLine(scanner, name);
+ }
+
+ private static void addLine(Scanner scanner, String name) {
+ try {
+ if (LineService.duplicateName(name)) {
+ throw new IllegalArgumentException(ScriptUtils.ERROR_DUPLICATE(Category.LINE));
+ }
+ addTerminals(scanner, name);
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+
+ private static void addTerminals(Scanner scanner, String name) {
+ List terminals = new ArrayList<>();
+ for (int i = 0; i < ScriptUtils.ASK_ADD_LINE.length; i++) {
+ String terminalName = lineView.additionalAsk(scanner, ScriptUtils.ASK_ADD_LINE[i]);
+ try {
+ if (!StationService.duplicateName(terminalName)) {
+ throw new IllegalArgumentException(ScriptUtils.ERROR_NO(Category.STATION));
+ }
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ return;
+ }
+ terminals.add(StationService.readStation(terminalName));
+ }
+ LineService.createLine(name, terminals);
+ }
+}
diff --git a/src/main/java/subway/controller/MenuController.java b/src/main/java/subway/controller/MenuController.java
new file mode 100644
index 000000000..b398e4656
--- /dev/null
+++ b/src/main/java/subway/controller/MenuController.java
@@ -0,0 +1,51 @@
+package subway.controller;
+
+import java.util.Scanner;
+import subway.domain.service.LineService;
+import subway.view.MenuView;
+import utils.Category;
+
+public class MenuController {
+ private MenuController() {}
+
+ public static void runProgram(Scanner scanner) {
+ MenuView mainView = new MenuView();
+ int stopOption = MenuView.RETRY;
+ while (stopOption < MenuView.EXIT) {
+ mainView.printMenu();
+ int selection = mainView.selectMenu(scanner);
+ if (selection <= MenuView.EXIT) {
+ stopOption = selection;
+ continue;
+ }
+ showSelectedView(selection, scanner);
+ }
+ }
+
+ private static void showSelectedView(int categoryNumber, Scanner scanner) {
+ Category category = Category.values()[categoryNumber];
+ MenuView selectedView = new MenuView(category);
+ selectedView.printMenu();
+ int selection = selectedView.selectMenu(scanner);
+ if (selection <= MenuView.EXIT) {
+ return;
+ }
+ executeSelection(category, selection, scanner);
+ }
+
+ public static void executeSelection(Category category, int selection, Scanner scanner) {
+ if (category == Category.STATION) {
+ StationController.manageStation(scanner, selection);
+ }
+ if (category == Category.LINE) {
+ if (selection == LineController.GET_LIST) {
+ LineService.readLineList();
+ return;
+ }
+ LineController.manageLine(scanner, selection);
+ }
+ if(category == Category.SECTION) {
+ SectionController.manageSection(scanner, selection);
+ }
+ }
+}
diff --git a/src/main/java/subway/controller/SectionController.java b/src/main/java/subway/controller/SectionController.java
new file mode 100644
index 000000000..243ec812c
--- /dev/null
+++ b/src/main/java/subway/controller/SectionController.java
@@ -0,0 +1,84 @@
+package subway.controller;
+
+import java.util.Scanner;
+import subway.domain.Line;
+import subway.domain.Station;
+import subway.domain.service.LineService;
+import subway.domain.service.SectionService;
+import subway.domain.service.StationService;
+import subway.view.DetailView;
+import utils.Category;
+import utils.ScriptUtils;
+
+public class SectionController {
+ private static DetailView sectionView = new DetailView(Category.SECTION);
+ private static int askCount = 2;
+ private static int ADD = 1;
+
+ private SectionController() { }
+
+ public static void manageSection(Scanner scanner, int selection) {
+ if (selection == ADD) {
+ addSection(scanner, selection);
+ return;
+ }
+
+ deleteSection(scanner, selection);
+ }
+
+ private static void deleteSection(Scanner scanner, int selection) {
+ Line line = askLine(scanner, selection);
+ Station station = askStation(scanner, selection);
+ if (line != null && station != null) {
+ SectionService.deleteSection(line, station);
+ }
+ }
+
+ private static void addSection(Scanner scanner, int selection) {
+ Line line = askLine(scanner, selection);
+ Station station = askStation(scanner, selection);
+ int idx = askIdx(scanner, selection, line);
+
+ if (line != null && station != null && idx >= 0) {
+ SectionService.createSection(line, station, idx);
+ }
+ }
+
+ private static int askIdx(Scanner scanner, int selection, Line line) {
+ int idx = sectionView.askSectionNumber(scanner, ScriptUtils.ASK_ANSWER_FOR_SECTION[selection-1][2]);
+ if (idx < 0) {
+ return idx;
+ }
+ try {
+ if (idx > line.getLength()) {
+ throw new IllegalArgumentException(ScriptUtils.ERROR_OUT_OF_BOUNDARY);
+ }
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ return -1;
+ }
+ return idx;
+ }
+
+ private static Station askStation(Scanner scanner, int selection) {
+ try {
+ String stationName = sectionView.askSection(scanner, ScriptUtils.ASK_ANSWER_FOR_SECTION[selection-1][1]);
+ SectionService.checkDuplicate(1, stationName);
+ return StationService.readStation(stationName);
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ return null;
+ }
+ }
+
+ private static Line askLine(Scanner scanner, int selection) {
+ try {
+ String lineName = sectionView.askSection(scanner, ScriptUtils.ASK_ANSWER_FOR_SECTION[selection-1][0]);
+ SectionService.checkDuplicate(0, lineName);
+ return LineService.readLine(lineName);
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ return null;
+ }
+ }
+}
diff --git a/src/main/java/subway/controller/StationController.java b/src/main/java/subway/controller/StationController.java
new file mode 100644
index 000000000..a7f4a13c4
--- /dev/null
+++ b/src/main/java/subway/controller/StationController.java
@@ -0,0 +1,33 @@
+package subway.controller;
+
+import java.util.Scanner;
+import subway.domain.service.StationService;
+import subway.view.DetailView;
+import utils.Category;
+
+public class StationController {
+ public static final int ADD = 1;
+ public static final int DELETE = 2;
+ public static final int GET_LIST = 3;
+
+ public static DetailView stationView = new DetailView(Category.STATION);
+
+ private StationController() {}
+
+ public static void manageStation(Scanner scanner, int selection) {
+ if (selection == GET_LIST) {
+ StationService.readStationList();
+ return;
+ }
+
+ String name = stationView.ask(scanner, selection);
+ if (name == null) {
+ return;
+ }
+ if (selection == ADD) {
+ StationService.createStation(name);
+ return;
+ }
+ StationService.deleteStation(name);
+ }
+}
diff --git a/src/main/java/subway/domain/Line.java b/src/main/java/subway/domain/Line.java
index f4d738d5a..335e4f5b4 100644
--- a/src/main/java/subway/domain/Line.java
+++ b/src/main/java/subway/domain/Line.java
@@ -1,15 +1,31 @@
package subway.domain;
+import java.util.List;
+
public class Line {
private String name;
+ private List stations;
- public Line(String name) {
+ public Line(String name, List terminals) {
this.name = name;
+ this.stations = terminals;
}
public String getName() {
return name;
}
- // ์ถ๊ฐ ๊ธฐ๋ฅ ๊ตฌํ
+ public int getLength() { return stations.size(); }
+
+ public boolean validateStation(Station station) {
+ return stations.contains(station);
+ }
+
+ public void addStation(Station station, int idx) {
+ stations.add(idx-1, station);
+ }
+
+ public void deleteStation(Station station) {
+ stations.remove(station);
+ }
}
diff --git a/src/main/java/subway/domain/LineRepository.java b/src/main/java/subway/domain/repository/LineRepository.java
similarity index 54%
rename from src/main/java/subway/domain/LineRepository.java
rename to src/main/java/subway/domain/repository/LineRepository.java
index 49132ddb6..5170865aa 100644
--- a/src/main/java/subway/domain/LineRepository.java
+++ b/src/main/java/subway/domain/repository/LineRepository.java
@@ -1,9 +1,11 @@
-package subway.domain;
+package subway.domain.repository;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
+import java.util.stream.Collectors;
+import subway.domain.Line;
public class LineRepository {
private static final List lines = new ArrayList<>();
@@ -19,4 +21,13 @@ public static void addLine(Line line) {
public static boolean deleteLineByName(String name) {
return lines.removeIf(line -> Objects.equals(line.getName(), name));
}
+
+ public static boolean findNoLine(String name) {
+ return lines.stream().noneMatch(line -> Objects.equals(line.getName(), name));
+ }
+
+ public static Line findLine(String name) {
+ return lines.stream().filter(line ->
+ Objects.equals(line.getName(), name)).collect(Collectors.toList()).get(0);
+ }
}
diff --git a/src/main/java/subway/domain/StationRepository.java b/src/main/java/subway/domain/repository/StationRepository.java
similarity index 53%
rename from src/main/java/subway/domain/StationRepository.java
rename to src/main/java/subway/domain/repository/StationRepository.java
index b7245c0f3..b0e68242a 100644
--- a/src/main/java/subway/domain/StationRepository.java
+++ b/src/main/java/subway/domain/repository/StationRepository.java
@@ -1,11 +1,14 @@
-package subway.domain;
+package subway.domain.repository;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
+import java.util.stream.Collectors;
+import subway.domain.Station;
public class StationRepository {
+
private static final List stations = new ArrayList<>();
public static List stations() {
@@ -19,4 +22,13 @@ public static void addStation(Station station) {
public static boolean deleteStation(String name) {
return stations.removeIf(station -> Objects.equals(station.getName(), name));
}
+
+ public static boolean findNoStation(String name) {
+ return stations.stream().noneMatch(station -> Objects.equals(station.getName(), name));
+ }
+
+ public static List readStation(String name) {
+ return StationRepository.stations().stream().filter(station ->
+ Objects.equals(station.getName(), name)).collect(Collectors.toList());
+ }
}
diff --git a/src/main/java/subway/domain/service/LineService.java b/src/main/java/subway/domain/service/LineService.java
new file mode 100644
index 000000000..e408ee6f6
--- /dev/null
+++ b/src/main/java/subway/domain/service/LineService.java
@@ -0,0 +1,74 @@
+package subway.domain.service;
+
+import java.util.Arrays;
+import java.util.List;
+import subway.domain.Line;
+import subway.domain.Station;
+import subway.domain.repository.LineRepository;
+
+import utils.Category;
+import utils.InitUtils;
+import utils.ScriptUtils;
+
+public class LineService {
+
+ private LineService() {
+ }
+
+ public static void init() {
+ for (int i = 0; i < InitUtils.INIT_LINES.length; i++) {
+ List terminals;
+ String[] terminalNames = InitUtils.INIT_TERMINALS[i];
+ terminals = Arrays.asList(
+ StationService.readStation(terminalNames[0]),
+ StationService.readStation(terminalNames[1])
+ );
+ createLine(InitUtils.INIT_LINES[i], terminals);
+ }
+ }
+
+ public static Line readLine(String name) {
+ return LineRepository.findLine(name);
+ }
+
+ public static void readLineList() {
+ System.out.println(ScriptUtils.LINE_LIST);
+ for (Line line : LineRepository.lines()) {
+ System.out.println(ScriptUtils.INFO + line.getName());
+ }
+ }
+
+ public static void createLine(String name, List terminalNames) {
+ try {
+ if (duplicateName(name)) {
+ throw new IllegalArgumentException(ScriptUtils.ERROR_DUPLICATE(Category.LINE));
+ }
+ } catch (IllegalArgumentException e) {
+ System.out.println();
+ return;
+ }
+ Line line = new Line(name, terminalNames);
+ LineRepository.addLine(line);
+ }
+
+ public static void deleteLine(String name) {
+ try {
+ if (!duplicateName(name)) {
+ throw new IllegalArgumentException(ScriptUtils.ERROR_NO(Category.LINE));
+ }
+ } catch (IllegalArgumentException e) {
+ System.out.println();
+ return;
+ }
+ LineRepository.deleteLineByName(name);
+ }
+
+ public static boolean duplicateName(String input) {
+ boolean notDuplicate = LineRepository.findNoLine(input);
+ if (notDuplicate) {
+ return false;
+ }
+ return true;
+ }
+
+}
diff --git a/src/main/java/subway/domain/service/SectionService.java b/src/main/java/subway/domain/service/SectionService.java
new file mode 100644
index 000000000..956622624
--- /dev/null
+++ b/src/main/java/subway/domain/service/SectionService.java
@@ -0,0 +1,44 @@
+package subway.domain.service;
+
+import subway.domain.Line;
+import subway.domain.Station;
+import utils.Category;
+import utils.ScriptUtils;
+
+public class SectionService {
+ public static final int ASK_LINE = 0;
+ public static final int ASK_STATION = 1;
+
+ public static void checkDuplicate(int askIdx, String answer) {
+ if (askIdx == ASK_LINE) {
+ if (!LineService.duplicateName(answer)) {
+ throw new IllegalArgumentException(ScriptUtils.ERROR_NO(Category.LINE));
+ }
+ }
+ if (askIdx == ASK_STATION) {
+ if (!StationService.duplicateName(answer)) {
+ throw new IllegalArgumentException(ScriptUtils.ERROR_NO(Category.STATION));
+ }
+ }
+ }
+
+ public static void createSection(Line line, Station station, int idx) {
+ try {
+ if (line.validateStation(station)) {
+ throw new IllegalArgumentException(ScriptUtils.ERROR_DUPLICATE(Category.STATION));
+ }
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ return;
+ }
+ line.addStation(station, idx);
+ }
+
+ public static void deleteSection(Line line, Station station) {
+ if (line.getLength() <= 2) {
+ System.out.println(ScriptUtils.ERROR_TOO_SMALL);
+ return;
+ }
+ line.deleteStation(station);
+ }
+}
diff --git a/src/main/java/subway/domain/service/StationService.java b/src/main/java/subway/domain/service/StationService.java
new file mode 100644
index 000000000..04b5540be
--- /dev/null
+++ b/src/main/java/subway/domain/service/StationService.java
@@ -0,0 +1,63 @@
+package subway.domain.service;
+
+import java.util.List;
+import java.util.stream.Collectors;
+import subway.domain.Station;
+import subway.domain.repository.StationRepository;
+import utils.Category;
+import utils.InitUtils;
+import utils.ScriptUtils;
+
+public class StationService {
+ private StationService() {}
+
+ public static void init() {
+ for (String station : InitUtils.INIT_STATIONS) {
+ createStation(station);
+ }
+ }
+
+ public static void createStation(String name) {
+ try {
+ if (duplicateName(name)) {
+ throw new IllegalArgumentException();
+ }
+ } catch (IllegalArgumentException e) {
+ System.out.println(ScriptUtils.ERROR_DUPLICATE(Category.STATION));
+ return;
+ }
+ Station station = new Station(name);
+ StationRepository.addStation(station);
+ }
+
+ public static void readStationList() {
+ System.out.println(ScriptUtils.STATION_LIST);
+ for (Station station : StationRepository.stations()) {
+ System.out.println(ScriptUtils.INFO + station.getName());
+ }
+ }
+
+ public static void deleteStation(String name) {
+ try {
+ if (!duplicateName(name)) {
+ throw new IllegalArgumentException();
+ }
+ } catch (IllegalArgumentException e) {
+ System.out.println(ScriptUtils.ERROR_NO(Category.STATION));
+ return;
+ }
+ StationRepository.deleteStation(name);
+ }
+
+ public static boolean duplicateName(String input) {
+ boolean notDuplicate = StationRepository.findNoStation(input);
+ if (notDuplicate) {
+ return false;
+ }
+ return true;
+ }
+
+ public static Station readStation(String name) {
+ return StationRepository.readStation(name).get(0);
+ }
+}
diff --git a/src/main/java/subway/view/DetailView.java b/src/main/java/subway/view/DetailView.java
new file mode 100644
index 000000000..871b592ee
--- /dev/null
+++ b/src/main/java/subway/view/DetailView.java
@@ -0,0 +1,70 @@
+package subway.view;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Scanner;
+import subway.domain.repository.StationRepository;
+import utils.Category;
+import utils.ScriptUtils;
+
+public class DetailView {
+ private Category category;
+ private int ADD = 1;
+ private int DELETE = 2;
+
+ public DetailView(Category category) {
+ this.category = category;
+ }
+
+ public String ask(Scanner scanner, int selection) {
+ System.out.println(ScriptUtils.ASK_ANSWER_FOR(category, selection));
+ return inputName(scanner);
+ }
+
+ public String askSection(Scanner scanner, String script) {
+ System.out.println(script);
+ return inputName(scanner);
+ }
+
+ public int askSectionNumber(Scanner scanner, String script) {
+ System.out.println(script);
+ return inputInt(scanner);
+ }
+
+ private int inputInt(Scanner scanner) {
+ String input = scanner.nextLine();
+ try {
+ return Integer.parseInt(input);
+ } catch (IllegalArgumentException e) {
+ System.out.println(ScriptUtils.ERROR_INVALIDATE_VALUE);
+ }
+ return -1;
+ }
+
+ public String additionalAsk(Scanner scanner, String ask) {
+ if (category == Category.LINE) {
+ System.out.println(ask);
+ String answer = inputName(scanner);
+ return answer;
+ }
+ return null;
+ }
+
+ public String inputName(Scanner scanner) {
+ String input = scanner.nextLine();
+ try {
+ return validateName(input);
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ return null;
+ }
+
+ private String validateName(String input) {
+ if (input.length() < 2) {
+ throw new IllegalArgumentException(ScriptUtils.ERROR_TOO_SHORT(category));
+ }
+ return input;
+ }
+}
diff --git a/src/main/java/subway/view/MenuView.java b/src/main/java/subway/view/MenuView.java
new file mode 100644
index 000000000..52c381758
--- /dev/null
+++ b/src/main/java/subway/view/MenuView.java
@@ -0,0 +1,56 @@
+package subway.view;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Scanner;
+import utils.Category;
+import utils.ScriptUtils;
+
+public class MenuView {
+ public static final int EXIT = 0;
+ public static final int RETRY = -1;
+ public static final int START = 1;
+ public static final int[] LENGTH_OF_MENU = {4, 3, 3, 2};
+
+ private Category category;
+ List exitValue;
+
+ public MenuView() {
+ this.category = Category.MAIN;
+ this.exitValue = Arrays.asList("Q", "q");
+ }
+
+ public MenuView(Category category) {
+ this.category = category;
+ this.exitValue = Arrays.asList("B", "b");
+ }
+
+ public void printMenu() {
+ System.out.println(ScriptUtils.MENUS[category.ordinal()]);
+ }
+
+ public int selectMenu(Scanner scanner) {
+ System.out.println(ScriptUtils.ASK_SELECTION);
+ String input = scanner.nextLine();
+
+ if (exitValue.contains(input)) {
+ return EXIT;
+ }
+ return validateSelection(input);
+ }
+
+ public int validateSelection(String input) {
+ int number;
+
+ try {
+ number = Integer.parseInt(input);
+ if (number < START || number > LENGTH_OF_MENU[category.ordinal()]) {
+ throw new IllegalArgumentException();
+ }
+ } catch (IllegalArgumentException e) {
+ System.out.println(ScriptUtils.ERROR_OUT_OF_VALUE);
+ return RETRY;
+ }
+ return number;
+ }
+}
diff --git a/src/main/java/utils/Category.java b/src/main/java/utils/Category.java
new file mode 100644
index 000000000..f3a94e5f2
--- /dev/null
+++ b/src/main/java/utils/Category.java
@@ -0,0 +1,15 @@
+package utils;
+
+public enum Category {
+ MAIN("๋ฉ์ธ"), STATION("์ญ"), LINE("๋
ธ์ "), SECTION("๊ตฌ๊ฐ");
+
+ private String korean;
+
+ Category(String name) {
+ this.korean = name;
+ }
+
+ public String getKorean() {
+ return korean;
+ }
+}
diff --git a/src/main/java/utils/InitUtils.java b/src/main/java/utils/InitUtils.java
new file mode 100644
index 000000000..81bd04d9a
--- /dev/null
+++ b/src/main/java/utils/InitUtils.java
@@ -0,0 +1,15 @@
+package utils;
+
+public class InitUtils {
+ public static final String[] INIT_STATIONS = {
+ "๊ต๋์ญ", "๊ฐ๋จ์ญ", "์ญ์ผ์ญ", "๋จ๋ถํฐ๋ฏธ๋์ญ", "์์ฌ์ญ", "์์ฌ์๋ฏผ์์ฒ์ญ", "๋งค๋ด์ญ"
+ };
+
+ public static final String[] INIT_LINES = {
+ "2ํธ์ ", "3ํธ์ ", "์ ๋ถ๋น์ "
+ };
+
+ public static final String[][] INIT_TERMINALS = {
+ {"๊ต๋์ญ", "์ญ์ผ์ญ"}, {"๊ต๋์ญ", "๋งค๋ด์ญ"}, {"๊ฐ๋จ์ญ", "์์ฌ์๋ฏผ์์ฒ์ญ"}
+ };
+}
diff --git a/src/main/java/utils/ScriptUtils.java b/src/main/java/utils/ScriptUtils.java
new file mode 100644
index 000000000..daecf5e78
--- /dev/null
+++ b/src/main/java/utils/ScriptUtils.java
@@ -0,0 +1,49 @@
+package utils;
+
+public class ScriptUtils {
+
+ public static final String[] MENUS = {
+ "\n## ๋ฉ์ธ ํ๋ฉด\n1. ์ญ ๊ด๋ฆฌ\n2. ๋
ธ์ ๊ด๋ฆฌ\n3. ๊ตฌ๊ฐ ๊ด๋ฆฌ\n4. ์งํ์ฒ ๋
ธ์ ๋ ์ถ๋ ฅ\nQ. ์ข
๋ฃ\n",
+ "\n## ์ญ ๊ด๋ฆฌ ํ๋ฉด\n1. ์ญ ๋ฑ๋ก\n2. ์ญ ์ญ์ \n3. ์ญ ์กฐํ\nB. ๋์๊ฐ๊ธฐ\n",
+ "\n## ๋
ธ์ ๊ด๋ฆฌ ํ๋ฉด\n1. ๋
ธ์ ๋ฑ๋ก\n2. ๋
ธ์ ์ญ์ \n3. ๋
ธ์ ์กฐํ\nB. ๋์๊ฐ๊ธฐ\n",
+ "\n## ๊ตฌ๊ฐ ๊ด๋ฆฌ ํ๋ฉด\n1. ๊ตฌ๊ฐ ๋ฑ๋ก\n2. ๊ตฌ๊ฐ ์ญ์ \nB. ๋์๊ฐ๊ธฐ\n"
+ };
+ public static final String STATION_LIST = "## ์ญ ๋ชฉ๋ก";
+ public static final String LINE_LIST = "## ๋
ธ์ ๋ชฉ๋ก";
+ public static final String INFO = "[INFO] ";
+ public static final String ASK_SELECTION = "## ์ํ๋ ๊ธฐ๋ฅ์ ์ ํํ์ธ์.";
+ public static final String ERROR_INVALIDATE_VALUE = "\n[ERROR] ์ซ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.";
+ public static final String ERROR_OUT_OF_BOUNDARY = "\n[ERROR] ๋
ธ์ ๋ฒ์๋ฅผ ๋์ด์ญ๋๋ค.";
+ public static final String ERROR_TOO_SMALL = "\n[ERROR] ๋
ธ์ ์ ์ญ์ด 2๊ฐ ๋ฐ์ ์์ด ์ญ์ ๊ฐ ๋ถ๊ฐํฉ๋๋ค.";
+
+ public static final String ASK_ANSWER_FOR(Category category, int selection) {
+ if (selection == 1) {
+ return "\n## ๋ฑ๋กํ " + category.getKorean() + " ์ด๋ฆ์ ์
๋ ฅํ์ธ์.";
+ }
+ return "\n## ์ญ์ ํ " + category.getKorean()+ " ์ด๋ฆ์ ์
๋ ฅํ์ธ์.";
+ }
+
+ public static final String[] ASK_ADD_LINE = {
+ "## ๋ฑ๋กํ ๋
ธ์ ์ ์ํ ์ข
์ ์ญ ์ด๋ฆ์ ์
๋ ฅํ์ธ์.",
+ "## ๋ฑ๋กํ ๋
ธ์ ์ ํํ ์ข
์ ์ญ ์ด๋ฆ์ ์
๋ ฅํ์ธ์."
+ };
+
+ public static final String ERROR_OUT_OF_VALUE = "\n[ERROR] ์ ํํ ์ ์๋ ๊ธฐ๋ฅ์
๋๋ค.\n";
+
+ public static String ERROR_TOO_SHORT(Category category) {
+ return "\n[ERROR] " + category.getKorean() + " ์ด๋ฆ์ 2์ ์ด์์ด์ด์ผ ํฉ๋๋ค.\n";
+ }
+
+ public static String ERROR_DUPLICATE(Category category) {
+ return "\n[ERROR] ์ด๋ฏธ ๋ฑ๋ก๋ " + category.getKorean() + " ์ด๋ฆ์
๋๋ค.\n";
+ }
+
+ public static String ERROR_NO(Category category) {
+ return "\n[ERROR] ์กด์ฌํ์ง ์๋ " + category.getKorean() + " ์ด๋ฆ์
๋๋ค.\n";
+ }
+
+ public static String[][] ASK_ANSWER_FOR_SECTION = {
+ {"\n## ๋
ธ์ ์ ์
๋ ฅํ์ธ์.", "\n## ์ญ์ด๋ฆ์ ์
๋ ฅํ์ธ์.", "\n## ์์๋ฅผ ์
๋ ฅํ์ธ์."},
+ {}
+ };
+}