diff --git a/README.md b/README.md
index d6299154c..1654bf6e1 100644
--- a/README.md
+++ b/README.md
@@ -3,251 +3,14 @@
-## ๐ ๊ธฐ๋ฅ ์๊ตฌ์ฌํญ
-
-> ํ๋ฆฌ์ฝ์ค 3์ฃผ์ฐจ ๋ฏธ์
์์ ์ฌ์ฉํ ์ฝ๋๋ฅผ ์ฐธ๊ณ ํด๋ ๋ฌด๊ดํ๋ค.
-
-### ์ด๊ธฐ ์ค์
-- ํ๋ก๊ทธ๋จ ์์ ์ ์ญ, ๋
ธ์ , ๊ตฌ๊ฐ ์ ๋ณด๋ฅผ ์ด๊ธฐ ์ค์ ํด์ผ ํ๋ค.
-- ๊ฑฐ๋ฆฌ์ ์์ ์๊ฐ์ ์์ ์ ์์ด๋ฉฐ ๋จ์๋ km์ ๋ถ์ ์๋ฏธํ๋ค.
-- ์๋์ ์ฌ์ ๋ฑ๋ก ์ ๋ณด๋ก ๋ฐ๋์ ์ด๊ธฐ ์ค์ ์ ํ๋ค.
-
-```
- 1. ์งํ์ฒ ์ญ์ผ๋ก ๊ต๋์ญ, ๊ฐ๋จ์ญ, ์ญ์ผ์ญ, ๋จ๋ถํฐ๋ฏธ๋์ญ, ์์ฌ์ญ, ์์ฌ์๋ฏผ์์ฒ์ญ, ๋งค๋ด์ญ์ด ๋ฑ๋ก๋์ด ์๋ค.
- 2. ์งํ์ฒ ๋
ธ์ ์ผ๋ก 2ํธ์ , 3ํธ์ , ์ ๋ถ๋น์ ์ด ๋ฑ๋ก๋์ด ์๋ค.
- 3. ๋
ธ์ ์ ์ญ์ด ์๋์ ๊ฐ์ด ๋ฑ๋ก๋์ด ์๋ค.(์ผ์ชฝ ๋์ด ์ํ ์ข
์ )
- - 2ํธ์ : ๊ต๋์ญ - ( 2km / 3๋ถ ) - ๊ฐ๋จ์ญ - ( 2km / 3๋ถ ) - ์ญ์ผ์ญ
- - 3ํธ์ : ๊ต๋์ญ - ( 3km / 2๋ถ ) - ๋จ๋ถํฐ๋ฏธ๋์ญ - ( 6km / 5๋ถ ) - ์์ฌ์ญ - ( 1km / 1๋ถ ) - ๋งค๋ด์ญ
- - ์ ๋ถ๋น์ : ๊ฐ๋จ์ญ - ( 2km / 8๋ถ ) - ์์ฌ์ญ - ( 10km / 3๋ถ ) - ์์ฌ์๋ฏผ์์ฒ์ญ
- ```
-
-### ๊ฒฝ๋ก ์กฐํ ๊ธฐ๋ฅ
-- ์ถ๋ฐ์ญ๊ณผ ๋์ฐฉ์ญ์ ์
๋ ฅ๋ฐ์ ๊ฒฝ๋ก๋ฅผ ์กฐํํ๋ค.
-- ๊ฒฝ๋ก ์กฐํ ์ ์ด ๊ฑฐ๋ฆฌ, ์ด ์์ ์๊ฐ๋ ํจ๊ป ์ถ๋ ฅํ๋ค.
-- ๊ฒฝ๋ก ์กฐํ ๊ธฐ์ค์ `์ต๋จ ๊ฑฐ๋ฆฌ` `์ต์ ์๊ฐ`์ด ์๋ค.
-
-### ์์ธ ์ฒ๋ฆฌ
-- ๊ฒฝ๋ก ์กฐํ ์ ์ถ๋ฐ์ญ๊ณผ ๋์ฐฉ์ญ์ด ๊ฐ์ผ๋ฉด ์๋ฌ๋ฅผ ์ถ๋ ฅํ๋ค.
-- ๊ฒฝ๋ก ์กฐํ ์ ์ถ๋ฐ์ญ๊ณผ ๋์ฐฉ์ญ์ด ์ฐ๊ฒฐ๋์ด ์์ง ์์ผ๋ฉด ์๋ฌ๋ฅผ ์ถ๋ ฅํ๋ค.
-- ๊ทธ ์ธ ์ ์์ ์ผ๋ก ํ๋ก๊ทธ๋จ์ด ์ํ๋์ง ์์ ๊ฒฝ์ฐ ์๋ฌ๋ฅผ ์ถ๋ ฅํ๋ค.
-
-
-
-## โ๐ป ์
์ถ๋ ฅ ์๊ตฌ์ฌํญ
-- `ํ๋ก๊ทธ๋๋ฐ ์คํ ๊ฒฐ๊ณผ ์์`์ ๋์ผํ๊ฒ ์
์ถ๋ ฅ์ ๊ตฌํํ๋ค.
-- ๊ธฐ๋ํ๋ ์ถ๋ ฅ ๊ฒฐ๊ณผ๋ `[INFO]`๋ฅผ ๋ถ์ฌ์ ์ถ๋ ฅํ๋ค. ์ถ๋ ฅ๊ฐ์ ํ์์ ์์์ ๋์ผํ๊ฒ ํ๋ค.
-- ์๋ฌ ๋ฐ์ ์ `[ERROR]`๋ฅผ ๋ถ์ฌ์ ์ถ๋ ฅํ๋ค. ์๋ฌ์ ๋ฌธ๊ตฌ๋ ์์ ๋กญ๊ฒ ์์ฑํ๋ค.
-
-### ๐ป ํ๋ก๊ทธ๋๋ฐ ์คํ ๊ฒฐ๊ณผ ์์
-#### ๊ฒฝ๋ก ์กฐํ
-```
-## ๋ฉ์ธ ํ๋ฉด
-1. ๊ฒฝ๋ก ์กฐํ
-Q. ์ข
๋ฃ
-
-## ์ํ๋ ๊ธฐ๋ฅ์ ์ ํํ์ธ์.
-1
-
-## ๊ฒฝ๋ก ๊ธฐ์ค
-1. ์ต๋จ ๊ฑฐ๋ฆฌ
-2. ์ต์ ์๊ฐ
-B. ๋์๊ฐ๊ธฐ
-
-## ์ํ๋ ๊ธฐ๋ฅ์ ์ ํํ์ธ์.
-1
-
-## ์ถ๋ฐ์ญ์ ์
๋ ฅํ์ธ์.
-๊ต๋์ญ
-
-## ๋์ฐฉ์ญ์ ์
๋ ฅํ์ธ์.
-์์ฌ์ญ
-
-## ์กฐํ ๊ฒฐ๊ณผ
-[INFO] ---
-[INFO] ์ด ๊ฑฐ๋ฆฌ: 6km
-[INFO] ์ด ์์ ์๊ฐ: 14๋ถ
-[INFO] ---
-[INFO] ๊ต๋์ญ
-[INFO] ๊ฐ๋จ์ญ
-[INFO] ์์ฌ์ญ
-
-## ๋ฉ์ธ ํ๋ฉด
-1. ๊ฒฝ๋ก ์กฐํ
-Q. ์ข
๋ฃ
-
-...
-```
-
-#### ์๋ฌ ์ถ๋ ฅ ์์
-
-```
-## ๋ฉ์ธ ํ๋ฉด
-1. ๊ฒฝ๋ก ์กฐํ
-Q. ์ข
๋ฃ
-
-## ์ํ๋ ๊ธฐ๋ฅ์ ์ ํํ์ธ์.
-1
-
-## ๊ฒฝ๋ก ๊ธฐ์ค
-1. ์ต๋จ ๊ฑฐ๋ฆฌ
-2. ์ต์ ์๊ฐ
-B. ๋์๊ฐ๊ธฐ
-
-## ์ํ๋ ๊ธฐ๋ฅ์ ์ ํํ์ธ์.
-1
-
-## ์ถ๋ฐ์ญ์ ์
๋ ฅํ์ธ์.
-๊ฐ๋จ์ญ
-
-## ๋์ฐฉ์ญ์ ์
๋ ฅํ์ธ์.
-๊ฐ๋จ์ญ
-
-[ERROR] ์ถ๋ฐ์ญ๊ณผ ๋์ฐฉ์ญ์ด ๋์ผํฉ๋๋ค.
-
-## ๊ฒฝ๋ก ๊ธฐ์ค
-1. ์ต๋จ ๊ฑฐ๋ฆฌ
-2. ์ต์ ์๊ฐ
-B. ๋์๊ฐ๊ธฐ
-
-## ์ํ๋ ๊ธฐ๋ฅ์ ์ ํํ์ธ์.
-
-...
-
-```
-
-
-
-## ๐ฑ ํ๋ก๊ทธ๋๋ฐ ์๊ตฌ์ฌํญ
-- ์๋ฐ ์ฝ๋ ์ปจ๋ฒค์
์ ์งํค๋ฉด์ ํ๋ก๊ทธ๋๋ฐํ๋ค.
- - ๊ธฐ๋ณธ์ ์ผ๋ก [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html)์ ์์น์ผ๋ก ํ๋ค.
- - ๋จ, ๋ค์ฌ์ฐ๊ธฐ๋ '2 spaces'๊ฐ ์๋ '4 spaces'๋ก ํ๋ค.
-- indent(์ธ๋ดํธ, ๋ค์ฌ์ฐ๊ธฐ) depth๋ฅผ 3์ด ๋์ง ์๋๋ก ๊ตฌํํ๋ค. 2๊น์ง๋ง ํ์ฉํ๋ค.
- - ์๋ฅผ ๋ค์ด while๋ฌธ ์์ if๋ฌธ์ด ์์ผ๋ฉด ๋ค์ฌ์ฐ๊ธฐ๋ 2์ด๋ค.
- - ํํธ: indent(์ธ๋ดํธ, ๋ค์ฌ์ฐ๊ธฐ) depth๋ฅผ ์ค์ด๋ ์ข์ ๋ฐฉ๋ฒ์ ํจ์(๋๋ ๋ฉ์๋)๋ฅผ ๋ถ๋ฆฌํ๋ฉด ๋๋ค.
-- 3ํญ ์ฐ์ฐ์๋ฅผ ์ฐ์ง ์๋๋ค.
-- ํจ์(๋๋ ๋ฉ์๋)์ ๊ธธ์ด๊ฐ 15๋ผ์ธ์ ๋์ด๊ฐ์ง ์๋๋ก ๊ตฌํํ๋ค.
- - ํจ์(๋๋ ๋ฉ์๋)๊ฐ ํ ๊ฐ์ง ์ผ๋ง ์ ํ๋๋ก ๊ตฌํํ๋ค.
-- else ์์ฝ์ด๋ฅผ ์ฐ์ง ์๋๋ค.
- - ํํธ: if ์กฐ๊ฑด์ ์์ ๊ฐ์ returnํ๋ ๋ฐฉ์์ผ๋ก ๊ตฌํํ๋ฉด else๋ฅผ ์ฌ์ฉํ์ง ์์๋ ๋๋ค.
- - else๋ฅผ ์ฐ์ง ๋ง๋ผ๊ณ ํ๋ switch/case๋ก ๊ตฌํํ๋ ๊ฒฝ์ฐ๊ฐ ์๋๋ฐ switch/case๋ ํ์ฉํ์ง ์๋๋ค.
-- ํ๋ก๊ทธ๋๋ฐ ์๊ตฌ์ฌํญ์์ ๋ณ๋๋ก ๋ณ๊ฒฝ ๋ถ๊ฐ ์๋ด๊ฐ ์๋ ๊ฒฝ์ฐ ํ์ผ ์์ ๊ณผ ํจํค์ง ์ด๋์ ์์ ๋กญ๊ฒ ํ ์ ์๋ค.
-- ์์ธ ์ํฉ ์ ์๋ฌ ๋ฌธ๊ตฌ๋ฅผ ์ถ๋ ฅํด์ผ ํ๋ค. ๋จ, ์๋ฌ ๋ฌธ๊ตฌ๋ `[ERROR]` ๋ก ์์ํด์ผ ํ๋ค.
-
-### ํ๋ก๊ทธ๋๋ฐ ์๊ตฌ์ฌํญ - Application
-- Application ํด๋์ค๋ฅผ ํ์ฉํด ๊ตฌํํด์ผ ํ๋ค.
-- Application์ ํจํค์ง ๊ตฌ์กฐ๋ ๋ณ๊ฒฝํ์ง ์๋๋ค.
-- Application ํด๋์ค์ ์๋ Scanner๋ฅผ ์ฌ์ฉํ๊ณ ๋ณ๋์ Scanner ๊ฐ์ฒด๋ฅผ ๋ง๋ค์ง ์๋๋ค.
-```java
-public class Application {
- public static void main(String[] args) {
- final Scanner scanner = new Scanner(System.in);
- ...
- }
-}
-```
-
-### ํ๋ก๊ทธ๋๋ฐ ์๊ตฌ์ฌํญ - Station, Line
-- Station, Line ํด๋์ค๋ฅผ ํ์ฉํ์ฌ ์งํ์ฒ ์ญ๊ณผ ๋
ธ์ ์ ๊ตฌํํด์ผ ํ๋ค.
-- ์ ๊ณตํ๋ ๊ฐ ํด๋์ค์ ๊ธฐ๋ณธ ์์ฑ์๋ฅผ ์ถ๊ฐํ ์ ์๋ค.
-- ํ๋(์ธ์คํด์ค ๋ณ์)์ธ name์ ์ ๊ทผ ์ ์ด์ private์ ๋ณ๊ฒฝํ ์ ์๋ค.
-- ๊ฐ๋ฅํ๋ฉด setter ๋ฉ์๋(ex. setXXX)๋ฅผ ์ถ๊ฐํ์ง ์๊ณ ๊ตฌํํ๋ค.
-
-```java
-public class Station {
- private String name;
-
- public Station(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- // ์ถ๊ฐ ๊ธฐ๋ฅ ๊ตฌํ
-}
-
-```
-
-### ํ๋ก๊ทธ๋๋ฐ ์๊ตฌ์ฌํญ - StationRepository, LineRepository
-- Station๊ณผ Line์ ์ํ๋ฅผ ์ ์ฅํ ์ ์๋ StationRepository, LineRepository๋ฅผ ์ ๊ณตํ๋ค.
-- ํ์ ์ StationRepository, LineRepository ์ด ์ธ ์ถ๊ฐ๋ก Repository๋ฅผ ๋ง๋ค ์ ์๋ค.
-- ์ถ๊ฐ๋ก ์์ฑ๋๋ ๊ฐ์ฒด์ ๋ํด์ XXXRepository ๋ค์ด๋ฐ์ผ๋ก ์ ์ฅ ํด๋์ค๋ฅผ ์ถ๊ฐํ๋ค.
-- ๊ฐ์ฒด๋ค์ ์ํ๋ฅผ ๊ด๋ฆฌํ๊ธฐ ์ํด์ XXXRepository ํด๋์ค๋ฅผ ํ์ฉํด ์ ์ฅ ๋ก์ง์ ๊ตฌํํด์ผ ํ๋ค.
-- ์์ฑ๋ ๋ฉ์๋๋ ์์ ํ ์ ์๊ณ , ํ์์ ๋ฐ๋ผ ๋ฉ์๋๋ฅผ ์์ ๋กญ๊ฒ ์ถ๊ฐํ ์ ์๋ค.
-
-```java
-public class StationRepository {
- private static final List stations = new ArrayList<>();
-
- public static List stations() {
- return Collections.unmodifiableList(stations);
- }
-
- public static void addStation(Station station) {
- stations.add(station);
- }
-
- public static boolean deleteStation(String name) {
- return stations.removeIf(station -> Objects.equals(station.getName(), name));
- }
-
- public static void deleteAll() {
- stations.clear();
- }
-}
-```
-
-
-
-## โ๏ธํํธ
-### ์ต๋จ ๊ฒฝ๋ก ๋ผ์ด๋ธ๋ฌ๋ฆฌ
-- jgrapht ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ํ์ฉํ๋ฉด ๊ฐํธํ๊ฒ ์ต๋จ๊ฑฐ๋ฆฌ๋ฅผ ์กฐํํ ์ ์์
-- Dijkstra ์๊ณ ๋ฆฌ์ฆ์ ๋ฐ๋์ ์ดํดํ ํ์๋ ์๊ณ ๋ฏธ์
์ ์ ์ฉํ ์ ๋๋ก๋ง ์ดํดํ๋ฉด ๋จ
-- JGraphtTest ํด๋์ค์ ํ
์คํธ๋ฅผ ํ์ฉํ์ฌ ๋ฏธ์
์ ํ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๊ธฐ๋ฅ์ ํ์ตํ ์ ์์
-- ์ ์ (vertex)๊ณผ ๊ฐ์ (edge), ๊ทธ๋ฆฌ๊ณ ๊ฐ์ค์น ๊ฐ๋
์ ์ด์ฉ
- - ์ ์ : ์งํ์ฒ ์ญ
- - ๊ฐ์ : ์งํ์ฒ ์ญ ์ฐ๊ฒฐ์ ๋ณด
- - ๊ฐ์ค์น: ๊ฑฐ๋ฆฌ or ์์ ์๊ฐ
-- ์ต๋จ ๊ฑฐ๋ฆฌ ๊ธฐ์ค ์กฐํ ์ ๊ฐ์ค์น๋ฅผ ๊ฑฐ๋ฆฌ๋ก ์ค์
-
-```java
-@Test
-public void getDijkstraShortestPath() {
- WeightedMultigraph graph
- = new WeightedMultigraph(DefaultWeightedEdge.class);
- graph.addVertex("v1");
- graph.addVertex("v2");
- graph.addVertex("v3");
- graph.setEdgeWeight(graph.addEdge("v1", "v2"), 2);
- graph.setEdgeWeight(graph.addEdge("v2", "v3"), 2);
- graph.setEdgeWeight(graph.addEdge("v1", "v3"), 100);
-
- DijkstraShortestPath dijkstraShortestPath = new DijkstraShortestPath(graph);
- List shortestPath = dijkstraShortestPath.getPath("v3", "v1").getVertexList();
-
- assertThat(shortestPath.size()).isEqualTo(3);
-}
-```
-
-#### ํ
์คํธ ์ค๋ช
-
-
-
-- ์ญ ์ฌ์ด์ ๊ฑฐ๋ฆฌ๋ฅผ ๊ณ ๋ คํ์ง ์๋ ๊ฒฝ์ฐ V1->V3 ๊ฒฝ๋ก๊ฐ ์ต๋จ ๊ฒฝ๋ก
-- ์ญ ์ฌ์ด์ ๊ฑฐ๋ฆฌ๋ฅผ ๊ณ ๋ คํ ๊ฒฝ์ฐ V1->V3 ๊ฒฝ๋ก์ ๊ฑฐ๋ฆฌ๋ 100km, V1->V2->V3 ๊ฒฝ๋ก์ ๊ฑฐ๋ฆฌ๋ 4km์ด๋ฏ๋ก ์ต๋จ ๊ฒฝ๋ก๋ V1->V2->V3
-
-
-
-## ๐ ์งํ ์๊ตฌ์ฌํญ
-- ๋ฏธ์
์ [java-subway-path-precourse ์ ์ฅ์](https://github.com/woowacourse/java-subway-path-precourse) ๋ฅผ fork/cloneํด ์์ํ๋ค.
-- ๊ธฐ๋ฅ์ ๊ตฌํํ๊ธฐ ์ ์ java-subway-path-precourse/docs/README.md ํ์ผ์ ๊ตฌํํ ๊ธฐ๋ฅ ๋ชฉ๋ก์ ์ ๋ฆฌํด ์ถ๊ฐํ๋ค.
-- git์ commit ๋จ์๋ ์ ๋จ๊ณ์์ README.md ํ์ผ์ ์ ๋ฆฌํ ๊ธฐ๋ฅ ๋ชฉ๋ก ๋จ์๋ก ์ถ๊ฐํ๋ค.
- - [AngularJS Commit Message Conventions](https://gist.github.com/stephenparish/9941e89d80e2bc58a153) ์ฐธ๊ณ ํด commit log๋ฅผ ๋จ๊ธด๋ค.
-- [ํ๋ฆฌ์ฝ์ค ๊ณผ์ ์ ์ถ ๋ฌธ์](https://github.com/woowacourse/woowacourse-docs/tree/master/precourse) ์ ์ฐจ๋ฅผ ๋ฐ๋ผ ๋ฏธ์
์ ์ ์ถํ๋ค.
- - [ํ๋ฆฌ์ฝ์ค ๊ณผ์ FAQ](https://github.com/woowacourse/woowacourse-docs/tree/master/precourse/faq) ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ์ฌ ์งํํ ์ ์๋ค.
-
-
-## ๐ License
-
-This project is [MIT](https://github.com/woowacourse/java-subway-path-precourse/blob/master/LICENSE.md) licensed.
+## ๊ตฌํํ ๊ธฐ๋ฅ ๋ชฉ๋ก
+
+- ์ญ, ๋
ธ์ , ๊ตฌ๊ฐ ์ ๋ณด ์ด๊ธฐํ(๋จ์ km, ๋ถ)
+ - ์ฌ์ฉ์ ์
๋ ฅ ๋ฐ๋ ๋ถ๋ถ์ด ์๋๊ธฐ ๋๋ฌธ์ ์์ธ์ฒ๋ฆฌ๋ฅผ ํด์ฃผ์ง ์์๋ค.
+- ๋ฉ์ธ ํ๋ฉด์์ ๊ธฐ๋ฅ ์ ํ
+ - ์์ธ ์ฒ๋ฆฌ : ์ ํ ๊ฐ๋ฅํ์ง ์์ ๊ธฐ๋ฅ ๋ฒํธ ์
๋ ฅ
+- ์ถ๋ฐ์ญ, ๋์ฐฉ์ญ ์
๋ ฅ๋ฐ๊ธฐ
+ - ์์ธ ์ฒ๋ฆฌ : ์ญ ๋ชฉ๋ก์ ์กด์ฌํ์ง ์๋ ์
๋ ฅ, ๊ฐ์ ์ด๋ฆ์ ์ญ์ ๋ฐ์ ๊ฒฝ์ฐ
+- ๊ฒฝ๋ก ์กฐํ ์ ๊ฑฐ๋ฆฌ, ์๊ฐ ๊ธฐ์ค
+- ์ด ๊ฑฐ๋ฆฌ, ์ด ์์์๊ฐ, ์ง๋์จ ๊ตฌ๊ฐ ์ถ๋ ฅ
+- ๋ค์ต์คํธ๋ผ๋ฅผ ํ์ฉํ์ฌ ๊ฒฝ๋ก ๊ตฌํ๊ธฐ
\ No newline at end of file
diff --git a/src/main/java/subway/Application.java b/src/main/java/subway/Application.java
index 0bcf786cc..65a95c9a9 100644
--- a/src/main/java/subway/Application.java
+++ b/src/main/java/subway/Application.java
@@ -6,5 +6,8 @@ public class Application {
public static void main(String[] args) {
final Scanner scanner = new Scanner(System.in);
// TODO: ํ๋ก๊ทธ๋จ ๊ตฌํ
+ User user = new User(scanner);
+ SubwayManagement subwayManagement = new SubwayManagement(user);
+ subwayManagement.start();
}
}
diff --git a/src/main/java/subway/Constants.java b/src/main/java/subway/Constants.java
new file mode 100644
index 000000000..fe3b5322c
--- /dev/null
+++ b/src/main/java/subway/Constants.java
@@ -0,0 +1,11 @@
+package subway;
+
+public class Constants {
+ public static final String FUNCTION_ONE = "1";
+ public static final String FUNCTION_TWO = "2";
+ public static final String FUNCTION_Q = "Q";
+ public static final String FUNCTION_B = "B";
+ public static final String TIME_COST = "TIME";
+ public static final String DISTANCE_COST = "DISTANCE";
+ public static final int ERROR_CODE = -1;
+}
diff --git a/src/main/java/subway/FindPath.java b/src/main/java/subway/FindPath.java
new file mode 100644
index 000000000..8d318e2ed
--- /dev/null
+++ b/src/main/java/subway/FindPath.java
@@ -0,0 +1,165 @@
+package subway;
+
+import subway.domain.NodeData;
+import subway.domain.Station;
+import subway.domain.StationRepository;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.PriorityQueue;
+import java.util.Stack;
+
+public class FindPath {
+
+ private static final int INIT_MIN_VALUE = 0;
+ private static final int MAX_VALUE = 99999999;
+
+ private static ArrayList> subwayList;
+ private static int dist[];
+ private static boolean visited[];
+ private static int parent[];
+ private static int stationSize;
+ private static PriorityQueue q;
+
+ public static void start(String select, String startStation, String arriveStation) {
+ setBeforeDijkstra(select, startStation);
+ int minCost = startDijkstra(startStation, arriveStation);
+ if (minCost == MAX_VALUE) {
+ throw new IllegalArgumentException("[ERROR] ์๋ก ์ฐ๊ฒฐ๋์ด ์์ง ์์ ์ญ์
๋๋ค.");
+ }
+ String kind = Constants.DISTANCE_COST;
+ if (select.equals(Constants.FUNCTION_TWO)) {
+ kind = Constants.TIME_COST;
+ }
+ int anotherMinCost = traceMinCost(findNumberByName(startStation), findNumberByName(arriveStation), select);
+ Stack stack = tracePath(findNumberByName(startStation), findNumberByName(arriveStation));
+ PrintScreen.printMinPathStationToArrive(kind, stack, minCost, anotherMinCost);
+ }
+
+ private static int traceMinCost(int startNumber, int endNumber, String kind) {
+ if (kind.equals(Constants.FUNCTION_ONE)) {
+ kind = Constants.TIME_COST;
+ }
+ if (kind.equals(Constants.FUNCTION_TWO)) {
+ kind = Constants.DISTANCE_COST;
+ }
+ int minCost = 0;
+ int cur = endNumber;
+
+ while (cur != startNumber) {
+ minCost += StationRepository.getCost(findNameByNumber(cur), findNameByNumber(parent[cur]), kind);
+ cur = parent[cur];
+ }
+ return minCost;
+ }
+
+ private static Stack tracePath(int startNumber, int endNumber) {
+ Stack stack = new Stack<>();
+ int cur = endNumber;
+
+ while (cur != startNumber) {
+ stack.push(findNameByNumber(cur));
+ cur = parent[cur];
+ }
+ stack.push(findNameByNumber(cur));
+ return stack;
+ }
+
+ //depth 2์ดํ๋ก ๊ณ ์น๊ธฐ, ๋ฉ์๋ 15์ค ์ดํ
+ private static int startDijkstra(String startStation, String arriveStation) {
+ int startNumber = findNumberByName(startStation);
+ int arriveNumber = findNumberByName(arriveStation);
+ dist[startNumber] = INIT_MIN_VALUE;
+ visited[startNumber] = true;
+
+ while (!q.isEmpty()) {
+ Pair p = q.poll();
+
+ int start = p.start;
+
+ for (int i = 0; i < subwayList.get(start).size(); i++) {
+ int end = subwayList.get(start).get(i).end;
+ int cost = subwayList.get(start).get(i).cost;
+ if (!visited[end]) {
+ if (dist[end] > dist[start] + cost) {
+ dist[end] = dist[start] + cost;
+ q.add(new Pair(end, 0, dist[end]));
+ parent[end] = start;
+ }
+ }
+ }
+ visited[start] = true;
+ }
+
+ return dist[arriveNumber];
+ }
+
+ private static void setBeforeDijkstra(String select, String startStation) {
+ subwayList = new ArrayList>();
+ stationSize = StationRepository.getSize();
+ setSubwayList(select);
+ dist = new int[stationSize];
+ visited = new boolean[stationSize];
+ parent = new int[stationSize];
+ Arrays.fill(dist, MAX_VALUE);
+ q = new PriorityQueue<>();
+
+ q.add(new Pair(findNumberByName(startStation), 0, 0));
+ }
+
+ private static void setSubwayList(String select) {
+ for (int i = 0; i < stationSize; i++) {
+ subwayList.add(new ArrayList());
+ }
+
+ for (int i = 0; i < stationSize; i++) {
+ Station station = StationRepository.stations().get(i);
+ for (NodeData nodeData : station.getNodeData()) {
+ int cost = selectDistanceOrTime(select, nodeData);
+ subwayList.get(i).add(new Pair(findNumberByName(nodeData.getBeforeStation()), findNumberByName(nodeData.getNextStation()), cost));
+ }
+ }
+ }
+
+ private static String findNameByNumber(int number) {
+ return StationRepository.stations().get(number).getName();
+ }
+
+ private static int findNumberByName(String name) {
+ for (int i = 0; i < stationSize; i++) {
+
+ if (StationRepository.stations().get(i).getName().equals(name)) {
+ return i;
+ }
+ }
+
+ return Constants.ERROR_CODE;
+ }
+
+ private static int selectDistanceOrTime(String select, NodeData nodeData) {
+ if (select.equals(Constants.FUNCTION_ONE)) {
+ return nodeData.getDistanceCost();
+ }
+ if (select.equals(Constants.FUNCTION_TWO)) {
+ return nodeData.getTimeCost();
+ }
+
+ return Constants.ERROR_CODE;
+ }
+
+ public static class Pair implements Comparable {
+ int start, end, cost;
+
+ Pair(int start, int end, int cost) {
+ this.start = start;
+ this.end = end;
+ this.cost = cost;
+ }
+
+ @Override
+ public int compareTo(Pair o) {
+ // TODO Auto-generated method stub
+ return this.cost - o.cost;
+ }
+ }
+}
diff --git a/src/main/java/subway/InitSetting.java b/src/main/java/subway/InitSetting.java
new file mode 100644
index 000000000..88bf4cc43
--- /dev/null
+++ b/src/main/java/subway/InitSetting.java
@@ -0,0 +1,56 @@
+package subway;
+
+import subway.domain.Line;
+import subway.domain.LineRepository;
+import subway.domain.Station;
+import subway.domain.StationRepository;
+
+public class InitSetting {
+
+ private static String[] initStation = {"๊ต๋์ญ", "๊ฐ๋จ์ญ", "์ญ์ผ์ญ", "๋จ๋ถํฐ๋ฏธ๋์ญ", "์์ฌ์ญ", "์์ฌ์๋ฏผ์์ฒ์ญ", "๋งค๋ด์ญ"};
+ private static String[] initLine = {"2ํธ์ ", "3ํธ์ ", "์ ๋ถ๋น์ "};
+ private static String[][] initSection = {{"๊ต๋์ญ", "๊ฐ๋จ์ญ", "์ญ์ผ์ญ"}, {"๊ต๋์ญ", "๋จ๋ถํฐ๋ฏธ๋์ญ", "์์ฌ์ญ", "๋งค๋ด์ญ"}, {"๊ฐ๋จ์ญ", "์์ฌ์ญ", "์์ฌ์๋ฏผ์์ฒ์ญ"}};
+ // "km, ๋ถ"
+ private static String[][] initCost = {{"2,3", "2,3"}, {"3,2", "6,5", "1,1"}, {"2,8", "10,3"}};
+
+
+ public static void initSetting() {
+ setInitStation();
+ setInitLine();
+ setInitSection();
+ setInitCost();
+ }
+
+ private static void setInitStation() {
+ for (String name : initStation) {
+ StationRepository.addStation(new Station(name));
+ }
+ }
+
+ private static void setInitLine() {
+ for (String name : initLine) {
+ LineRepository.addLine(new Line(name));
+ }
+ }
+
+ private static void setInitSection() {
+ for (int i = 0; i < initSection.length; i++) {
+ for (String name : initSection[i]) {
+ LineRepository.addSection(i, name);
+ }
+ }
+ }
+
+ private static void setInitCost() {
+ for (int i = 0; i < initCost.length; i++) {
+ for (int j = 0; j < initCost[i].length; j++) {
+ String[] cost = initCost[i][j].split(",");
+ int distanceCost = Integer.parseInt(cost[0]);
+ int timeCost = Integer.parseInt(cost[1]);
+ String curStation = initSection[i][j];
+ String nextStation = initSection[i][j + 1];
+ StationRepository.setCost(curStation, nextStation, timeCost, distanceCost);
+ }
+ }
+ }
+}
diff --git a/src/main/java/subway/PrintScreen.java b/src/main/java/subway/PrintScreen.java
new file mode 100644
index 000000000..99185332c
--- /dev/null
+++ b/src/main/java/subway/PrintScreen.java
@@ -0,0 +1,52 @@
+package subway;
+
+import java.util.Stack;
+
+public class PrintScreen {
+
+ public static void printMain() {
+ System.out.println("## ๋ฉ์ธ ํ๋ฉด");
+ System.out.println("1. ๊ฒฝ๋ก ์กฐํ");
+ System.out.println("Q. ์ข
๋ฃ");
+
+ selectFunction();
+ }
+
+ public static void selectFunction() {
+ System.out.println("\n## ์ํ๋ ๊ธฐ๋ฅ์ ์ ํํ์ธ์.");
+ }
+
+ public static void selectStandard() {
+ System.out.println("## ๊ฒฝ๋ก ๊ธฐ์ค");
+ System.out.println("1. ์ต๋จ ๊ฑฐ๋ฆฌ");
+ System.out.println("2. ์ต์ ์๊ฐ");
+ System.out.println("B. ๋์๊ฐ๊ธฐ");
+
+ selectFunction();
+ }
+
+ public static void printInputStartStation() {
+ System.out.println("## ์ถ๋ฐ์ญ์ ์
๋ ฅํ์ธ์.");
+ }
+
+ public static void printInputArriveStation() {
+ System.out.println("## ๋์ฐฉ์ญ์ ์
๋ ฅํ์ธ์.");
+ }
+
+ public static void printMinPathStationToArrive(String kind, Stack stack, int firstMinCost, int secondMinCost) {
+ System.out.println("[INFO] ---");
+ if (kind.equals(Constants.DISTANCE_COST)) {
+ System.out.println("[INFO] ์ด ๊ฑฐ๋ฆฌ : " + firstMinCost);
+ System.out.println("[INFO] ์ด ์์์๊ฐ : " + secondMinCost);
+ }
+ if (kind.equals(Constants.TIME_COST)) {
+ System.out.println("[INFO] ์ด ์์์๊ฐ : " + firstMinCost);
+ System.out.println("[INFO] ์ด ๊ฑฐ๋ฆฌ : " + secondMinCost);
+ }
+ System.out.println("[INFO] ---");
+ while (!stack.isEmpty()) {
+ System.out.println("[INFO] " + stack.pop());
+ }
+ System.out.println();
+ }
+}
diff --git a/src/main/java/subway/SubwayManagement.java b/src/main/java/subway/SubwayManagement.java
new file mode 100644
index 000000000..21ed09e17
--- /dev/null
+++ b/src/main/java/subway/SubwayManagement.java
@@ -0,0 +1,82 @@
+package subway;
+
+import subway.domain.StationRepository;
+
+public class SubwayManagement {
+
+ private User user;
+
+ public SubwayManagement(User user) {
+ this.user = user;
+ }
+
+ public void start() {
+
+ InitSetting.initSetting();
+
+ while (true) {
+ PrintScreen.printMain();
+ String select = user.getInput();
+ try {
+ checkMainSelect(select);
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ if (select.equals(Constants.FUNCTION_ONE)) {
+ findPathFunction();
+ }
+ if (select.equals(Constants.FUNCTION_Q)) {
+ break;
+ }
+ }
+ }
+
+ private void checkMainSelect(String select) {
+ if (!select.equals(Constants.FUNCTION_Q) && !select.equals(Constants.FUNCTION_ONE)) {
+ throw new IllegalArgumentException("[ERROR] ์ ํํ ์ ์๋ ๊ธฐ๋ฅ์
๋๋ค.\n");
+ }
+ }
+
+ private void findPathFunction() {
+ PrintScreen.selectStandard();
+ String select = user.getInput();
+ try {
+ checkFindPathSelect(select);
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ if (select.equals(Constants.FUNCTION_ONE) || select.equals(Constants.FUNCTION_TWO)) {
+ selectFindPathFunction(select);
+ }
+ }
+
+ private void checkFindPathSelect(String select) {
+ if (!select.equals(Constants.FUNCTION_ONE) && !select.equals(Constants.FUNCTION_TWO) && !select.equals(Constants.FUNCTION_B)) {
+ throw new IllegalArgumentException("[ERROR] ์ ํํ ์ ์๋ ๊ธฐ๋ฅ์
๋๋ค.\n");
+ }
+ }
+
+ private void selectFindPathFunction(String select) {
+ PrintScreen.printInputStartStation();
+ String startStation = user.getInput();
+ PrintScreen.printInputArriveStation();
+ String arriveStation = user.getInput();
+
+ try {
+ checkFindPathInput(startStation, arriveStation);
+ FindPath.start(select, startStation, arriveStation);
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ return;
+ }
+ }
+
+ private void checkFindPathInput(String startStation, String arriveStation) {
+ if (!StationRepository.isContain(startStation) || !StationRepository.isContain(arriveStation)) {
+ throw new IllegalArgumentException("[ERROR] ์กด์ฌํ์ง ์๋ ์ญ์
๋๋ค.\n");
+ }
+ if (startStation.equals(arriveStation)) {
+ throw new IllegalArgumentException("[ERROR] ์ถ๋ฐ์ญ๊ณผ ๋์ฐฉ์ญ์ ๊ฐ์ ์ ์์ต๋๋ค.\n");
+ }
+ }
+}
diff --git a/src/main/java/subway/User.java b/src/main/java/subway/User.java
new file mode 100644
index 000000000..7de1c3a59
--- /dev/null
+++ b/src/main/java/subway/User.java
@@ -0,0 +1,16 @@
+package subway;
+
+import java.util.Scanner;
+
+public class User {
+
+ private final Scanner scanner;
+
+ public User(Scanner scanner) {
+ this.scanner = scanner;
+ }
+
+ public String getInput() {
+ return scanner.nextLine();
+ }
+}
diff --git a/src/main/java/subway/domain/Line.java b/src/main/java/subway/domain/Line.java
index f4d738d5a..3c7427f86 100644
--- a/src/main/java/subway/domain/Line.java
+++ b/src/main/java/subway/domain/Line.java
@@ -1,7 +1,11 @@
package subway.domain;
+import java.util.ArrayList;
+import java.util.List;
+
public class Line {
private String name;
+ private List sections = new ArrayList<>();
public Line(String name) {
this.name = name;
@@ -12,4 +16,7 @@ public String getName() {
}
// ์ถ๊ฐ ๊ธฐ๋ฅ ๊ตฌํ
+ public void addStationInSection(String name) {
+ sections.add(new Station(name));
+ }
}
diff --git a/src/main/java/subway/domain/LineRepository.java b/src/main/java/subway/domain/LineRepository.java
index 2c4a723c9..d41305f8b 100644
--- a/src/main/java/subway/domain/LineRepository.java
+++ b/src/main/java/subway/domain/LineRepository.java
@@ -23,4 +23,8 @@ public static boolean deleteLineByName(String name) {
public static void deleteAll() {
lines.clear();
}
+
+ public static void addSection(int idx, String stationName) {
+ lines.get(idx).addStationInSection(stationName);
+ }
}
diff --git a/src/main/java/subway/domain/NodeData.java b/src/main/java/subway/domain/NodeData.java
new file mode 100644
index 000000000..c3a22c9cb
--- /dev/null
+++ b/src/main/java/subway/domain/NodeData.java
@@ -0,0 +1,31 @@
+package subway.domain;
+
+public class NodeData {
+ private Station beforeStation;
+ private Station nextStation;
+ private int timeCost;
+ private int distanceCost;
+
+ public NodeData(Station beforeStation, Station nextStation, int timeCost, int distanceCost) {
+ this.beforeStation = beforeStation;
+ this.nextStation = nextStation;
+ this.timeCost = timeCost;
+ this.distanceCost = distanceCost;
+ }
+
+ public String getBeforeStation() {
+ return beforeStation.getName();
+ }
+
+ public String getNextStation() {
+ return nextStation.getName();
+ }
+
+ public int getTimeCost() {
+ return timeCost;
+ }
+
+ public int getDistanceCost() {
+ return distanceCost;
+ }
+}
diff --git a/src/main/java/subway/domain/Station.java b/src/main/java/subway/domain/Station.java
index bdb142590..a87c0f193 100644
--- a/src/main/java/subway/domain/Station.java
+++ b/src/main/java/subway/domain/Station.java
@@ -1,7 +1,12 @@
package subway.domain;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
public class Station {
private String name;
+ private List nodeData = new ArrayList<>();
public Station(String name) {
this.name = name;
@@ -12,4 +17,11 @@ public String getName() {
}
// ์ถ๊ฐ ๊ธฐ๋ฅ ๊ตฌํ
+ public void addNodeData(String nextStation, int timeCost, int distanceCost){
+ nodeData.add(new NodeData(new Station(name), new Station(nextStation), timeCost, distanceCost));
+ }
+
+ public List getNodeData(){
+ return Collections.unmodifiableList(nodeData);
+ }
}
diff --git a/src/main/java/subway/domain/StationRepository.java b/src/main/java/subway/domain/StationRepository.java
index 8ed9d103f..81f483c5c 100644
--- a/src/main/java/subway/domain/StationRepository.java
+++ b/src/main/java/subway/domain/StationRepository.java
@@ -1,5 +1,7 @@
package subway.domain;
+import subway.Constants;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -23,4 +25,58 @@ public static boolean deleteStation(String name) {
public static void deleteAll() {
stations.clear();
}
+
+ public static boolean isContain(String name) {
+ for (Station station : stations) {
+ if (station.getName().equals(name)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public static int getSize() {
+ return stations.size();
+ }
+
+ public static int getCost(String firstStation, String secondStation, String kind) {
+ for (Station station : stations) {
+ if (station.getName().equals(firstStation)) {
+ return findNextStation(station, secondStation, kind);
+ }
+ }
+ return Constants.ERROR_CODE;
+ }
+
+ private static int findNextStation(Station station, String nextStation, String kind) {
+ for (NodeData nodeData : station.getNodeData()) {
+ if (nodeData.getNextStation().equals(nextStation)) {
+ return getTimeOrDistanceCost(nodeData, kind);
+ }
+ }
+ return Constants.ERROR_CODE;
+ }
+
+ private static int getTimeOrDistanceCost(NodeData nodeData, String kind) {
+ if (kind.equals(Constants.DISTANCE_COST)) {
+ return nodeData.getDistanceCost();
+ }
+ if (kind.equals(Constants.TIME_COST)) {
+ return nodeData.getTimeCost();
+ }
+
+ return Constants.ERROR_CODE;
+ }
+
+ public static void setCost(String prevStationName, String nextStationName, int timeCost, int distanceCost) {
+ for (int i = 0; i < stations.size(); i++) {
+ if (stations.get(i).getName().equals(prevStationName)) {
+ stations().get(i).addNodeData(nextStationName, timeCost, distanceCost);
+ }
+ if (stations.get(i).getName().equals(nextStationName)) {
+ stations.get(i).addNodeData(prevStationName, timeCost, distanceCost);
+ }
+ }
+ }
}