From 08850b15afe3080547115f9eaba49bb2e7c17c7b Mon Sep 17 00:00:00 2001 From: soongjamm Date: Sat, 19 Dec 2020 13:14:04 +0900 Subject: [PATCH 01/24] =?UTF-8?q?docs(readme.md):=20=EA=B5=AC=ED=98=84=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EB=AA=A9=EB=A1=9D=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 273 +++++------------------------------------------------- 1 file changed, 25 insertions(+), 248 deletions(-) diff --git a/README.md b/README.md index d6299154c..3bf59a2b6 100644 --- a/README.md +++ b/README.md @@ -3,251 +3,28 @@
-## ๐Ÿš€ ๊ธฐ๋Šฅ ์š”๊ตฌ์‚ฌํ•ญ - -> ํ”„๋ฆฌ์ฝ”์Šค 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. +## ๊ตฌํ˜„ ๊ธฐ๋Šฅ ๋ชฉ๋ก +- ๋ฉ”์ธ ํ™”๋ฉด์—์„œ ๊ฒฝ๋กœ ์กฐํšŒ์™€ ์ข…๋ฃŒ์ค‘ ์ž…๋ ฅ์„ ๋ฐ›๋Š”๋‹ค. (1: ๊ฒฝ๋กœ์กฐํšŒ, Q: ์ข…๋ฃŒ) +- ๊ฒฝ๋กœ ๊ธฐ์ค€์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. (1: ์ตœ๋‹จ๊ฑฐ๋ฆฌ, 2: ์ตœ์†Œ์‹œ๊ฐ„) +- ๊ฒฝ๋กœ๋ฅผ ์กฐํšŒํ•œ๋‹ค. + - ์ถœ๋ฐœ์—ญ์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. + - ๋„์ฐฉ์—ญ์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. + - (๊ฒฝ๋กœ ๊ธฐ์ค€) ์ถœ๋ฐœ์—ญ์—์„œ ๋„์ฐฉ์—ญ๊นŒ์ง€์˜ ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ์ตœ๋‹จ ๊ฑฐ๋ฆฌ์ธ ๊ฒฝ๋กœ๋ฅผ ๊ณ„์‚ฐํ•œ๋‹ค. + - (์‹œ๊ฐ„ ๊ธฐ์ค€) ์ถœ๋ฐœ์—ญ์—์„œ ๋„์ฐฉ์—ญ๊นŒ์ง€์˜ ์ด ์†Œ์š”์‹œ๊ฐ„์ด ๊ฐ€์žฅ ์งง์€ ๊ฒฝ๋กœ๋ฅผ ๊ณ„์‚ฐํ•œ๋‹ค. + - ์ฐพ์•„๋‚ธ ๊ฒฝ๋กœ์˜ ๊ฑฐ๋ฆฌ์™€ ์†Œ์š”์‹œ๊ฐ„์„ ์ถœ๋ ฅํ•œ๋‹ค. +- ์ข…๋ฃŒํ•œ๋‹ค. + +`์˜ˆ์™ธ์ฒ˜๋ฆฌ` +- ๋ฉ”์ธํ™”๋ฉด๊ณผ ๊ฒฝ๋กœ๊ธฐ์ค€ ์ž…๋ ฅํ™”๋ฉด์—์„œ ์ •ํ•ด์ง„ ํ‚ค์›Œ๋“œ๊ฐ€ ์•„๋‹Œ ์ž…๋ ฅ์€ ๋ชจ๋‘ ์˜ˆ์™ธ์ฒ˜๋ฆฌ +- ๊ฒฝ๋กœ์กฐํšŒ์‹œ ์ถœ๋ฐœ์—ญ๊ณผ ๋„์ฐฉ์—ญ์ด ๊ฐ™์€ ๊ฒฝ์šฐ +- ์ถœ๋ฐœ์—ญ๊ณผ ๋„์ฐฉ์—ญ์ด ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ + +## ๊ฐ์ฒด +- ์ถœ๋ ฅ +- ์ž…๋ ฅ +- ์—ญ +- ์—ญ ๋ ˆํฌ์ง€ํ† ๋ฆฌ +- ๋…ธ์„  +- ๋…ธ์„  ๋ ˆํฌ์ง€ํ† ๋ฆฌ +- ๊ตฌ๊ฐ„ +- ๊ตฌ๊ฐ„ ๋ ˆํฌ์ง€ํ† ๋ฆฌ \ No newline at end of file From 7a55d3275370ca43275f3f0a28269216fe87a93f Mon Sep 17 00:00:00 2001 From: soongjamm Date: Sat, 19 Dec 2020 13:25:54 +0900 Subject: [PATCH 02/24] =?UTF-8?q?feat(subway):=20=EA=B8=B0=EB=B3=B8=20?= =?UTF-8?q?=EB=BC=88=EB=8C=80=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1=20?= =?UTF-8?q?=EB=B0=8F=20readme.md=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +++ src/main/java/subway/Application.java | 2 +- src/main/java/subway/domain/InputView.java | 19 +++++++++++++++++++ src/main/java/subway/domain/Menu.java | 14 ++++++++++++++ src/main/java/subway/domain/OutputView.java | 16 ++++++++++++++++ src/main/java/subway/domain/Screen.java | 11 +++++++++++ src/main/java/subway/domain/Section.java | 4 ++++ .../java/subway/domain/SectionRepository.java | 4 ++++ 8 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/main/java/subway/domain/InputView.java create mode 100644 src/main/java/subway/domain/Menu.java create mode 100644 src/main/java/subway/domain/OutputView.java create mode 100644 src/main/java/subway/domain/Screen.java create mode 100644 src/main/java/subway/domain/Section.java create mode 100644 src/main/java/subway/domain/SectionRepository.java diff --git a/README.md b/README.md index 3bf59a2b6..630a30186 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,9 @@
## ๊ตฌํ˜„ ๊ธฐ๋Šฅ ๋ชฉ๋ก +- ๋ฉ”์ธ ํ™”๋ฉด์—์„œ ๋ฉ”๋‰ด๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. - ๋ฉ”์ธ ํ™”๋ฉด์—์„œ ๊ฒฝ๋กœ ์กฐํšŒ์™€ ์ข…๋ฃŒ์ค‘ ์ž…๋ ฅ์„ ๋ฐ›๋Š”๋‹ค. (1: ๊ฒฝ๋กœ์กฐํšŒ, Q: ์ข…๋ฃŒ) +- ๊ฒฝ๋กœ ๊ธฐ์ค€ ํ™”๋ฉด์—์„œ ๋ฉ”๋‰ด๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. - ๊ฒฝ๋กœ ๊ธฐ์ค€์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. (1: ์ตœ๋‹จ๊ฑฐ๋ฆฌ, 2: ์ตœ์†Œ์‹œ๊ฐ„) - ๊ฒฝ๋กœ๋ฅผ ์กฐํšŒํ•œ๋‹ค. - ์ถœ๋ฐœ์—ญ์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. @@ -20,6 +22,7 @@ - ์ถœ๋ฐœ์—ญ๊ณผ ๋„์ฐฉ์—ญ์ด ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ ## ๊ฐ์ฒด +- ํ™”๋ฉด ๊ด€๋ฆฌ ๊ฐ์ฒด - ์ถœ๋ ฅ - ์ž…๋ ฅ - ์—ญ diff --git a/src/main/java/subway/Application.java b/src/main/java/subway/Application.java index 0bcf786cc..686a23d35 100644 --- a/src/main/java/subway/Application.java +++ b/src/main/java/subway/Application.java @@ -5,6 +5,6 @@ public class Application { public static void main(String[] args) { final Scanner scanner = new Scanner(System.in); - // TODO: ํ”„๋กœ๊ทธ๋žจ ๊ตฌํ˜„ + } } diff --git a/src/main/java/subway/domain/InputView.java b/src/main/java/subway/domain/InputView.java new file mode 100644 index 000000000..c35b96339 --- /dev/null +++ b/src/main/java/subway/domain/InputView.java @@ -0,0 +1,19 @@ +package subway.domain; + +public class InputView { + public void enterMainMenu() { + + } + + public void enterCriteria() { + + } + + public void enterDepartualStation() { + + } + + public void enterArrivalStation() { + + } +} diff --git a/src/main/java/subway/domain/Menu.java b/src/main/java/subway/domain/Menu.java new file mode 100644 index 000000000..e421b33e8 --- /dev/null +++ b/src/main/java/subway/domain/Menu.java @@ -0,0 +1,14 @@ +package subway.domain; + +public class Menu { + public enum Main { + ROUTE_INQUIRY, + QUIT, + } + + public enum ROUTE_CRITERIA { + SHORTEST_PATH, + SHORTEST_TIME, + BACK, + } +} diff --git a/src/main/java/subway/domain/OutputView.java b/src/main/java/subway/domain/OutputView.java new file mode 100644 index 000000000..6e8795f0c --- /dev/null +++ b/src/main/java/subway/domain/OutputView.java @@ -0,0 +1,16 @@ +package subway.domain; + +public class OutputView { + public void printMainMenu() { + + } + + public void printCriteriaMenu() { + + } + + public void printRouteResult() { + + } + +} diff --git a/src/main/java/subway/domain/Screen.java b/src/main/java/subway/domain/Screen.java new file mode 100644 index 000000000..af05bf06e --- /dev/null +++ b/src/main/java/subway/domain/Screen.java @@ -0,0 +1,11 @@ +package subway.domain; + +public class Screen { + public void show() { + + } + + public void isEmpty() { + + } +} diff --git a/src/main/java/subway/domain/Section.java b/src/main/java/subway/domain/Section.java new file mode 100644 index 000000000..13ba72bea --- /dev/null +++ b/src/main/java/subway/domain/Section.java @@ -0,0 +1,4 @@ +package subway.domain; + +public class Section { +} diff --git a/src/main/java/subway/domain/SectionRepository.java b/src/main/java/subway/domain/SectionRepository.java new file mode 100644 index 000000000..a8ab2e5fb --- /dev/null +++ b/src/main/java/subway/domain/SectionRepository.java @@ -0,0 +1,4 @@ +package subway.domain; + +public class SectionRepository { +} From 2c026e030d84d4cdf1b386e08bfaa355416d3de4 Mon Sep 17 00:00:00 2001 From: soongjamm Date: Sat, 19 Dec 2020 13:52:16 +0900 Subject: [PATCH 03/24] =?UTF-8?q?feat(MainScreen):=20=EB=A9=94=EB=89=B4=20?= =?UTF-8?q?=ED=99=94=EB=A9=B4=20=EB=B0=8F=20=EC=9E=85=EB=A0=A5=20=EC=9A=94?= =?UTF-8?q?=EA=B5=AC=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 ++++++++ src/main/java/subway/Application.java | 8 ++++++ src/main/java/subway/domain/InputView.java | 10 +++---- src/main/java/subway/domain/MainScreen.java | 19 +++++++++++++ src/main/java/subway/domain/Menu.java | 21 ++++++++++++-- src/main/java/subway/domain/OutputView.java | 13 +++++++-- src/main/java/subway/domain/Screen.java | 11 -------- .../java/subway/domain/ScreenManager.java | 28 +++++++++++++++++++ src/main/java/subway/domain/ScreenModel.java | 5 ++++ src/main/java/subway/domain/Section.java | 2 ++ .../java/subway/domain/SectionRepository.java | 3 ++ 11 files changed, 111 insertions(+), 21 deletions(-) create mode 100644 src/main/java/subway/domain/MainScreen.java delete mode 100644 src/main/java/subway/domain/Screen.java create mode 100644 src/main/java/subway/domain/ScreenManager.java create mode 100644 src/main/java/subway/domain/ScreenModel.java diff --git a/README.md b/README.md index 630a30186..40a36c58e 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,18 @@
+## ๊ธฐ๋ณธ ์„ค์ • +- ์—ญ, ๋…ธ์„ , ๊ตฌ๊ฐ„์ •๋ณด๋ฅผ ์ดˆ๊ธฐ์„ค์ •ํ•œ๋‹ค. +- ๋…ธ์„ ์€ `์ƒํ–‰์ชฝ์—ญ`, `ํ•˜ํ–‰์ชฝ์—ญ`, `๊ฑฐ๋ฆฌ`, `์‹œ๊ฐ„` ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. +``` +1. ์ง€ํ•˜์ฒ ์—ญ์œผ๋กœ ๊ต๋Œ€์—ญ, ๊ฐ•๋‚จ์—ญ, ์—ญ์‚ผ์—ญ, ๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ, ์–‘์žฌ์—ญ, ์–‘์žฌ์‹œ๋ฏผ์˜์ˆฒ์—ญ, ๋งค๋ด‰์—ญ์ด ๋“ฑ๋ก๋˜์–ด ์žˆ๋‹ค. +2. ์ง€ํ•˜์ฒ  ๋…ธ์„ ์œผ๋กœ 2ํ˜ธ์„ , 3ํ˜ธ์„ , ์‹ ๋ถ„๋‹น์„ ์ด ๋“ฑ๋ก๋˜์–ด ์žˆ๋‹ค. +3. ๋…ธ์„ ์— ์—ญ์ด ์•„๋ž˜์™€ ๊ฐ™์ด ๋“ฑ๋ก๋˜์–ด ์žˆ๋‹ค.(์™ผ์ชฝ ๋์ด ์ƒํ–‰ ์ข…์ ) + - 2ํ˜ธ์„ : ๊ต๋Œ€์—ญ - ( 2km / 3๋ถ„ ) - ๊ฐ•๋‚จ์—ญ - ( 2km / 3๋ถ„ ) - ์—ญ์‚ผ์—ญ + - 3ํ˜ธ์„ : ๊ต๋Œ€์—ญ - ( 3km / 2๋ถ„ ) - ๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ - ( 6km / 5๋ถ„ ) - ์–‘์žฌ์—ญ - ( 1km / 1๋ถ„ ) - ๋งค๋ด‰์—ญ + - ์‹ ๋ถ„๋‹น์„ : ๊ฐ•๋‚จ์—ญ - ( 2km / 8๋ถ„ ) - ์–‘์žฌ์—ญ - ( 10km / 3๋ถ„ ) - ์–‘์žฌ์‹œ๋ฏผ์˜์ˆฒ์—ญ +``` + ## ๊ตฌํ˜„ ๊ธฐ๋Šฅ ๋ชฉ๋ก - ๋ฉ”์ธ ํ™”๋ฉด์—์„œ ๋ฉ”๋‰ด๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. - ๋ฉ”์ธ ํ™”๋ฉด์—์„œ ๊ฒฝ๋กœ ์กฐํšŒ์™€ ์ข…๋ฃŒ์ค‘ ์ž…๋ ฅ์„ ๋ฐ›๋Š”๋‹ค. (1: ๊ฒฝ๋กœ์กฐํšŒ, Q: ์ข…๋ฃŒ) diff --git a/src/main/java/subway/Application.java b/src/main/java/subway/Application.java index 686a23d35..f08e6a5e8 100644 --- a/src/main/java/subway/Application.java +++ b/src/main/java/subway/Application.java @@ -1,10 +1,18 @@ package subway; +import subway.domain.MainScreen; +import subway.domain.ScreenManager; + import java.util.Scanner; public class Application { public static void main(String[] args) { final Scanner scanner = new Scanner(System.in); + ScreenManager.add(new MainScreen()); + + while(!ScreenManager.isEmpty()) { + ScreenManager.show(ScreenManager.pop()); + } } } diff --git a/src/main/java/subway/domain/InputView.java b/src/main/java/subway/domain/InputView.java index c35b96339..39e50b0f3 100644 --- a/src/main/java/subway/domain/InputView.java +++ b/src/main/java/subway/domain/InputView.java @@ -1,19 +1,19 @@ package subway.domain; public class InputView { - public void enterMainMenu() { - + public static void enterFeature() { + System.out.println("์›ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์„ ํƒํ•˜์„ธ์š”."); } - public void enterCriteria() { + public static void enterCriteria() { } - public void enterDepartualStation() { + public static void enterDepartualStation() { } - public void enterArrivalStation() { + public static void enterArrivalStation() { } } diff --git a/src/main/java/subway/domain/MainScreen.java b/src/main/java/subway/domain/MainScreen.java new file mode 100644 index 000000000..b1cc97d12 --- /dev/null +++ b/src/main/java/subway/domain/MainScreen.java @@ -0,0 +1,19 @@ +package subway.domain; + +import java.util.Scanner; + +public class MainScreen implements ScreenModel{ + + public MainScreen(Scanner scanner) { + } + + public MainScreen() { + + } + + @Override + public void showMenu() { + OutputView.printMainMenu(); + InputView.enterFeature(); + } +} diff --git a/src/main/java/subway/domain/Menu.java b/src/main/java/subway/domain/Menu.java index e421b33e8..e46bae999 100644 --- a/src/main/java/subway/domain/Menu.java +++ b/src/main/java/subway/domain/Menu.java @@ -2,8 +2,25 @@ public class Menu { public enum Main { - ROUTE_INQUIRY, - QUIT, + ROUTE_INQUIRY("1", "๊ฒฝ๋กœ์กฐํšŒ"), + QUIT("Q", "์ข…๋ฃŒ"), + ; + + private String code; + private String korean; + + Main(String code, String korean) { + this.code = code; + this.korean = korean; + } + + public String getCode() { + return code; + } + + public String getKorean() { + return korean; + } } public enum ROUTE_CRITERIA { diff --git a/src/main/java/subway/domain/OutputView.java b/src/main/java/subway/domain/OutputView.java index 6e8795f0c..9b078b382 100644 --- a/src/main/java/subway/domain/OutputView.java +++ b/src/main/java/subway/domain/OutputView.java @@ -1,15 +1,22 @@ package subway.domain; public class OutputView { - public void printMainMenu() { + private static final String newLine = "\n"; + + public static void printMainMenu() { + String message = "## ๋ฉ”์ธ ํ™”๋ฉด" + newLine; + for (Menu.Main menu : Menu.Main.values()) { + message += String.format("%s. %s" + newLine, menu.getCode(), menu.getKorean() ); + } + System.out.println(message); } - public void printCriteriaMenu() { + public static void printCriteriaMenu() { } - public void printRouteResult() { + public static void printRouteResult() { } diff --git a/src/main/java/subway/domain/Screen.java b/src/main/java/subway/domain/Screen.java deleted file mode 100644 index af05bf06e..000000000 --- a/src/main/java/subway/domain/Screen.java +++ /dev/null @@ -1,11 +0,0 @@ -package subway.domain; - -public class Screen { - public void show() { - - } - - public void isEmpty() { - - } -} diff --git a/src/main/java/subway/domain/ScreenManager.java b/src/main/java/subway/domain/ScreenManager.java new file mode 100644 index 000000000..ab0b50b78 --- /dev/null +++ b/src/main/java/subway/domain/ScreenManager.java @@ -0,0 +1,28 @@ +package subway.domain; + +import java.util.Stack; + +public class ScreenManager { + private static Stack screens = new Stack<>(); + + + + public static boolean isEmpty() { + if(screens.isEmpty()) { + return true; + } + return false; + } + + public static void show(ScreenModel screen) { + screen.showMenu(); + } + + public static void add(ScreenModel screen) { + screens.push(screen); + } + + public static ScreenModel pop() { + return screens.pop(); + } +} diff --git a/src/main/java/subway/domain/ScreenModel.java b/src/main/java/subway/domain/ScreenModel.java new file mode 100644 index 000000000..dd2d43b85 --- /dev/null +++ b/src/main/java/subway/domain/ScreenModel.java @@ -0,0 +1,5 @@ +package subway.domain; + +public interface ScreenModel { + public void showMenu(); +} diff --git a/src/main/java/subway/domain/Section.java b/src/main/java/subway/domain/Section.java index 13ba72bea..94c93a11f 100644 --- a/src/main/java/subway/domain/Section.java +++ b/src/main/java/subway/domain/Section.java @@ -1,4 +1,6 @@ package subway.domain; public class Section { + public Section() { + } } diff --git a/src/main/java/subway/domain/SectionRepository.java b/src/main/java/subway/domain/SectionRepository.java index a8ab2e5fb..856ae488b 100644 --- a/src/main/java/subway/domain/SectionRepository.java +++ b/src/main/java/subway/domain/SectionRepository.java @@ -1,4 +1,7 @@ package subway.domain; public class SectionRepository { + public void addSection() { + + } } From f75ba57256fba6c416ae4cdc58fca01611dc2ec5 Mon Sep 17 00:00:00 2001 From: soongjamm Date: Sat, 19 Dec 2020 14:57:16 +0900 Subject: [PATCH 04/24] =?UTF-8?q?feat:=20=EB=A9=94=EC=9D=B8=ED=99=94?= =?UTF-8?q?=EB=A9=B4=EA=B3=BC=20=EA=B2=BD=EB=A1=9C=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=9E=85=EB=A0=A5=EC=9D=84=20=EB=B0=9B?= =?UTF-8?q?=EB=8A=94=20=EA=B2=83=20=EA=B9=8C=EC=A7=80=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/Application.java | 7 +++-- .../java/subway/domain/FeatureScreen.java | 13 ++++++++++ src/main/java/subway/domain/InputView.java | 18 ++++++++++--- src/main/java/subway/domain/MainScreen.java | 19 ++++++++++---- src/main/java/subway/domain/Menu.java | 22 +++++++++++++--- src/main/java/subway/domain/OutputView.java | 6 ++++- .../java/subway/domain/ScreenManager.java | 19 +++++++++++--- src/main/java/subway/domain/ScreenModel.java | 4 ++- .../subway/domain/SelectCriteriaScreen.java | 26 +++++++++++++++++++ 9 files changed, 114 insertions(+), 20 deletions(-) create mode 100644 src/main/java/subway/domain/FeatureScreen.java create mode 100644 src/main/java/subway/domain/SelectCriteriaScreen.java diff --git a/src/main/java/subway/Application.java b/src/main/java/subway/Application.java index f08e6a5e8..281e4175a 100644 --- a/src/main/java/subway/Application.java +++ b/src/main/java/subway/Application.java @@ -2,6 +2,7 @@ import subway.domain.MainScreen; import subway.domain.ScreenManager; +import subway.domain.ScreenModel; import java.util.Scanner; @@ -9,10 +10,12 @@ public class Application { public static void main(String[] args) { final Scanner scanner = new Scanner(System.in); - ScreenManager.add(new MainScreen()); + ScreenManager.addNextMenuScreen(new MainScreen(scanner)); while(!ScreenManager.isEmpty()) { - ScreenManager.show(ScreenManager.pop()); + ScreenModel nextScreen = ScreenManager.pop(); + ScreenManager.show(nextScreen); + nextScreen.apply(); } } } diff --git a/src/main/java/subway/domain/FeatureScreen.java b/src/main/java/subway/domain/FeatureScreen.java new file mode 100644 index 000000000..7993fb372 --- /dev/null +++ b/src/main/java/subway/domain/FeatureScreen.java @@ -0,0 +1,13 @@ +package subway.domain; + +import java.util.Scanner; + +public class FeatureScreen implements ScreenModel { + + private final Scanner scanner; + + public FeatureScreen(Scanner scanner) { + this.scanner = scanner; + } + +} diff --git a/src/main/java/subway/domain/InputView.java b/src/main/java/subway/domain/InputView.java index 39e50b0f3..cded69d9c 100644 --- a/src/main/java/subway/domain/InputView.java +++ b/src/main/java/subway/domain/InputView.java @@ -1,19 +1,29 @@ package subway.domain; +import java.util.Scanner; + public class InputView { - public static void enterFeature() { + + private final Scanner scanner; + + public InputView(Scanner scanner) { + this.scanner = scanner; + } + + public String enterFeature() { System.out.println("์›ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์„ ํƒํ•˜์„ธ์š”."); + return scanner.nextLine(); } - public static void enterCriteria() { + public void enterCriteria() { } - public static void enterDepartualStation() { + public void enterDepartualStation() { } - public static void enterArrivalStation() { + public void enterArrivalStation() { } } diff --git a/src/main/java/subway/domain/MainScreen.java b/src/main/java/subway/domain/MainScreen.java index b1cc97d12..1e82c4fcf 100644 --- a/src/main/java/subway/domain/MainScreen.java +++ b/src/main/java/subway/domain/MainScreen.java @@ -2,18 +2,27 @@ import java.util.Scanner; -public class MainScreen implements ScreenModel{ +public class MainScreen implements ScreenModel { + + private final Scanner scanner; public MainScreen(Scanner scanner) { + this.scanner = scanner; } - public MainScreen() { + @Override + public String showMenu() { + InputView inputView = new InputView(scanner); + OutputView.printMainMenu(); + return inputView.enterFeature(); } @Override - public void showMenu() { - OutputView.printMainMenu(); - InputView.enterFeature(); + public ScreenModel getNextMenuScreen(String input) { + if (input.equals( Menu.Main.ROUTE_INQUIRY.getCode())) { + return new SelectCriteriaScreen(scanner); + } + return null; } } diff --git a/src/main/java/subway/domain/Menu.java b/src/main/java/subway/domain/Menu.java index e46bae999..7c36c873d 100644 --- a/src/main/java/subway/domain/Menu.java +++ b/src/main/java/subway/domain/Menu.java @@ -24,8 +24,24 @@ public String getKorean() { } public enum ROUTE_CRITERIA { - SHORTEST_PATH, - SHORTEST_TIME, - BACK, + SHORTEST_PATH("1", "์ตœ๋‹จ ๊ฑฐ๋ฆฌ"), + SHORTEST_TIME("2", "์ตœ์†Œ ์‹œ๊ฐ„"), + BACK("B", "๋Œ์•„๊ฐ€๊ธฐ"); + + private String code; + private String korean; + + ROUTE_CRITERIA(String code, String korean) { + this.code = code; + this.korean = korean; + } + + public String getCode() { + return code; + } + + public String getKorean() { + return korean; + } } } diff --git a/src/main/java/subway/domain/OutputView.java b/src/main/java/subway/domain/OutputView.java index 9b078b382..5a1a16506 100644 --- a/src/main/java/subway/domain/OutputView.java +++ b/src/main/java/subway/domain/OutputView.java @@ -13,7 +13,11 @@ public static void printMainMenu() { } public static void printCriteriaMenu() { - + String message = "## ๊ฒฝ๋กœ ๊ธฐ์ค€" + newLine; + for (Menu.ROUTE_CRITERIA menu : Menu.ROUTE_CRITERIA.values()) { + message += String.format("%s. %s" + newLine, menu.getCode(), menu.getKorean() ); + } + System.out.println(message); } public static void printRouteResult() { diff --git a/src/main/java/subway/domain/ScreenManager.java b/src/main/java/subway/domain/ScreenManager.java index ab0b50b78..f008552ba 100644 --- a/src/main/java/subway/domain/ScreenManager.java +++ b/src/main/java/subway/domain/ScreenManager.java @@ -1,12 +1,13 @@ package subway.domain; +import java.util.Objects; import java.util.Stack; public class ScreenManager { + private static final String DONE = "-1"; private static Stack screens = new Stack<>(); - public static boolean isEmpty() { if(screens.isEmpty()) { return true; @@ -15,11 +16,21 @@ public static boolean isEmpty() { } public static void show(ScreenModel screen) { - screen.showMenu(); + String result = screen.showMenu(); + if (result == DONE) { + return; + } + // todo ์œ ํšจํ•œ ์ž…๋ ฅ์ธ์ง€ ๊ฒ€์ฆํ•œ๋‹ค. + + addNextMenuScreen(screen.getNextMenuScreen(result)); + } - public static void add(ScreenModel screen) { - screens.push(screen); + public static void addNextMenuScreen(ScreenModel nextScreen) { + if (Objects.isNull(nextScreen)) { + return; + } + screens.push(nextScreen); } public static ScreenModel pop() { diff --git a/src/main/java/subway/domain/ScreenModel.java b/src/main/java/subway/domain/ScreenModel.java index dd2d43b85..d8ee179a0 100644 --- a/src/main/java/subway/domain/ScreenModel.java +++ b/src/main/java/subway/domain/ScreenModel.java @@ -1,5 +1,7 @@ package subway.domain; public interface ScreenModel { - public void showMenu(); + public default String showMenu() {return null;} + public default ScreenModel getNextMenuScreen(String input) {return null;} + public default void apply() {} } diff --git a/src/main/java/subway/domain/SelectCriteriaScreen.java b/src/main/java/subway/domain/SelectCriteriaScreen.java new file mode 100644 index 000000000..10a279cdf --- /dev/null +++ b/src/main/java/subway/domain/SelectCriteriaScreen.java @@ -0,0 +1,26 @@ +package subway.domain; + +import java.util.Scanner; + +public class SelectCriteriaScreen implements ScreenModel { + + private static final String DONE = "-1"; + private final Scanner scanner; + + public SelectCriteriaScreen(Scanner scanner) { + this.scanner = scanner; + } + + @Override + public String showMenu() { + InputView inputView = new InputView(scanner); + + OutputView.printCriteriaMenu(); + String input = inputView.enterFeature(); + if (input.equals(Menu.Main.QUIT)) { + return DONE; + } + return input; + } + +} From 1e9f42faf6ea944481db7e003b73ffefc689da1b Mon Sep 17 00:00:00 2001 From: soongjamm Date: Sat, 19 Dec 2020 14:58:56 +0900 Subject: [PATCH 05/24] =?UTF-8?q?refactor:=20=ED=8C=A8=ED=82=A4=EC=A7=80?= =?UTF-8?q?=EB=A5=BC=20=EC=83=9D=EC=84=B1=ED=95=B4=EC=84=9C=20=EA=B0=81=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A5=BC=20=EC=9D=B4=EB=8F=99?= =?UTF-8?q?=EC=8B=9C=ED=82=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/Application.java | 6 +++--- src/main/java/subway/{domain => menu}/Menu.java | 2 +- src/main/java/subway/{domain => screen}/FeatureScreen.java | 2 +- src/main/java/subway/{domain => screen}/MainScreen.java | 6 +++++- src/main/java/subway/{domain => screen}/ScreenManager.java | 2 +- src/main/java/subway/{domain => screen}/ScreenModel.java | 2 +- .../subway/{domain => screen}/SelectCriteriaScreen.java | 6 +++++- src/main/java/subway/{domain => view}/InputView.java | 2 +- src/main/java/subway/{domain => view}/OutputView.java | 4 +++- 9 files changed, 21 insertions(+), 11 deletions(-) rename src/main/java/subway/{domain => menu}/Menu.java (97%) rename src/main/java/subway/{domain => screen}/FeatureScreen.java (89%) rename src/main/java/subway/{domain => screen}/MainScreen.java (84%) rename src/main/java/subway/{domain => screen}/ScreenManager.java (97%) rename src/main/java/subway/{domain => screen}/ScreenModel.java (89%) rename src/main/java/subway/{domain => screen}/SelectCriteriaScreen.java (83%) rename src/main/java/subway/{domain => view}/InputView.java (95%) rename src/main/java/subway/{domain => view}/OutputView.java (94%) diff --git a/src/main/java/subway/Application.java b/src/main/java/subway/Application.java index 281e4175a..c75c34ae7 100644 --- a/src/main/java/subway/Application.java +++ b/src/main/java/subway/Application.java @@ -1,8 +1,8 @@ package subway; -import subway.domain.MainScreen; -import subway.domain.ScreenManager; -import subway.domain.ScreenModel; +import subway.screen.MainScreen; +import subway.screen.ScreenManager; +import subway.screen.ScreenModel; import java.util.Scanner; diff --git a/src/main/java/subway/domain/Menu.java b/src/main/java/subway/menu/Menu.java similarity index 97% rename from src/main/java/subway/domain/Menu.java rename to src/main/java/subway/menu/Menu.java index 7c36c873d..a7c979808 100644 --- a/src/main/java/subway/domain/Menu.java +++ b/src/main/java/subway/menu/Menu.java @@ -1,4 +1,4 @@ -package subway.domain; +package subway.menu; public class Menu { public enum Main { diff --git a/src/main/java/subway/domain/FeatureScreen.java b/src/main/java/subway/screen/FeatureScreen.java similarity index 89% rename from src/main/java/subway/domain/FeatureScreen.java rename to src/main/java/subway/screen/FeatureScreen.java index 7993fb372..e4b8c0974 100644 --- a/src/main/java/subway/domain/FeatureScreen.java +++ b/src/main/java/subway/screen/FeatureScreen.java @@ -1,4 +1,4 @@ -package subway.domain; +package subway.screen; import java.util.Scanner; diff --git a/src/main/java/subway/domain/MainScreen.java b/src/main/java/subway/screen/MainScreen.java similarity index 84% rename from src/main/java/subway/domain/MainScreen.java rename to src/main/java/subway/screen/MainScreen.java index 1e82c4fcf..181e35859 100644 --- a/src/main/java/subway/domain/MainScreen.java +++ b/src/main/java/subway/screen/MainScreen.java @@ -1,4 +1,8 @@ -package subway.domain; +package subway.screen; + +import subway.menu.Menu; +import subway.view.InputView; +import subway.view.OutputView; import java.util.Scanner; diff --git a/src/main/java/subway/domain/ScreenManager.java b/src/main/java/subway/screen/ScreenManager.java similarity index 97% rename from src/main/java/subway/domain/ScreenManager.java rename to src/main/java/subway/screen/ScreenManager.java index f008552ba..5f84e7c2e 100644 --- a/src/main/java/subway/domain/ScreenManager.java +++ b/src/main/java/subway/screen/ScreenManager.java @@ -1,4 +1,4 @@ -package subway.domain; +package subway.screen; import java.util.Objects; import java.util.Stack; diff --git a/src/main/java/subway/domain/ScreenModel.java b/src/main/java/subway/screen/ScreenModel.java similarity index 89% rename from src/main/java/subway/domain/ScreenModel.java rename to src/main/java/subway/screen/ScreenModel.java index d8ee179a0..f77e8fc1f 100644 --- a/src/main/java/subway/domain/ScreenModel.java +++ b/src/main/java/subway/screen/ScreenModel.java @@ -1,4 +1,4 @@ -package subway.domain; +package subway.screen; public interface ScreenModel { public default String showMenu() {return null;} diff --git a/src/main/java/subway/domain/SelectCriteriaScreen.java b/src/main/java/subway/screen/SelectCriteriaScreen.java similarity index 83% rename from src/main/java/subway/domain/SelectCriteriaScreen.java rename to src/main/java/subway/screen/SelectCriteriaScreen.java index 10a279cdf..5df610e61 100644 --- a/src/main/java/subway/domain/SelectCriteriaScreen.java +++ b/src/main/java/subway/screen/SelectCriteriaScreen.java @@ -1,4 +1,8 @@ -package subway.domain; +package subway.screen; + +import subway.menu.Menu; +import subway.view.InputView; +import subway.view.OutputView; import java.util.Scanner; diff --git a/src/main/java/subway/domain/InputView.java b/src/main/java/subway/view/InputView.java similarity index 95% rename from src/main/java/subway/domain/InputView.java rename to src/main/java/subway/view/InputView.java index cded69d9c..5ef69f9f7 100644 --- a/src/main/java/subway/domain/InputView.java +++ b/src/main/java/subway/view/InputView.java @@ -1,4 +1,4 @@ -package subway.domain; +package subway.view; import java.util.Scanner; diff --git a/src/main/java/subway/domain/OutputView.java b/src/main/java/subway/view/OutputView.java similarity index 94% rename from src/main/java/subway/domain/OutputView.java rename to src/main/java/subway/view/OutputView.java index 5a1a16506..5ab97eb3c 100644 --- a/src/main/java/subway/domain/OutputView.java +++ b/src/main/java/subway/view/OutputView.java @@ -1,4 +1,6 @@ -package subway.domain; +package subway.view; + +import subway.menu.Menu; public class OutputView { From 835d997139c54b62d9100f9404d2aa75db12b76e Mon Sep 17 00:00:00 2001 From: soongjamm Date: Sat, 19 Dec 2020 15:28:30 +0900 Subject: [PATCH 06/24] =?UTF-8?q?feat(Section):=20=EA=B5=AC=EA=B0=84=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EB=8B=B4=EB=8A=94=20Section=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=EC=9D=98=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9E=90=EC=99=80=20SectionRepository=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EA=B5=AC=EA=B0=84=20=EC=B6=94=EA=B0=80=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/Application.java | 1 - src/main/java/subway/domain/Section.java | 12 +++++++++++- src/main/java/subway/screen/FeatureScreen.java | 10 +++++++++- src/main/java/subway/screen/MainScreen.java | 4 ++-- src/main/java/subway/screen/ScreenManager.java | 4 ++-- src/main/java/subway/screen/ScreenModel.java | 5 ++--- .../java/subway/screen/SelectCriteriaScreen.java | 7 ++++++- 7 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/main/java/subway/Application.java b/src/main/java/subway/Application.java index c75c34ae7..7eef3eb1c 100644 --- a/src/main/java/subway/Application.java +++ b/src/main/java/subway/Application.java @@ -15,7 +15,6 @@ public static void main(String[] args) { while(!ScreenManager.isEmpty()) { ScreenModel nextScreen = ScreenManager.pop(); ScreenManager.show(nextScreen); - nextScreen.apply(); } } } diff --git a/src/main/java/subway/domain/Section.java b/src/main/java/subway/domain/Section.java index 94c93a11f..3ea378c25 100644 --- a/src/main/java/subway/domain/Section.java +++ b/src/main/java/subway/domain/Section.java @@ -1,6 +1,16 @@ package subway.domain; public class Section { - public Section() { + private Station departureStation; + private Station arriavalStation; + private int distance; + private int costTime; + + public Section(Station departureStation, Station arriavalStation, int distance, int costTime) { + this.departureStation = departureStation; + this.arriavalStation = arriavalStation; + this.distance = distance; + this.costTime = costTime; } + } diff --git a/src/main/java/subway/screen/FeatureScreen.java b/src/main/java/subway/screen/FeatureScreen.java index e4b8c0974..fde51e6d3 100644 --- a/src/main/java/subway/screen/FeatureScreen.java +++ b/src/main/java/subway/screen/FeatureScreen.java @@ -5,9 +5,17 @@ public class FeatureScreen implements ScreenModel { private final Scanner scanner; + private final String input; - public FeatureScreen(Scanner scanner) { + public FeatureScreen(Scanner scanner, String input) { this.scanner = scanner; + this.input = input; + } + + @Override + public String showScreen() { + System.out.println("์ตœ๋‹จ๊ฑฐ๋ฆฌ๋‚˜ ์ตœ์†Œ์‹œ๊ฐ„ ์‹คํ–‰"); + return "-1"; } } diff --git a/src/main/java/subway/screen/MainScreen.java b/src/main/java/subway/screen/MainScreen.java index 181e35859..d6dabed15 100644 --- a/src/main/java/subway/screen/MainScreen.java +++ b/src/main/java/subway/screen/MainScreen.java @@ -15,7 +15,7 @@ public MainScreen(Scanner scanner) { } @Override - public String showMenu() { + public String showScreen() { InputView inputView = new InputView(scanner); OutputView.printMainMenu(); @@ -23,7 +23,7 @@ public String showMenu() { } @Override - public ScreenModel getNextMenuScreen(String input) { + public ScreenModel getNextScreen(String input) { if (input.equals( Menu.Main.ROUTE_INQUIRY.getCode())) { return new SelectCriteriaScreen(scanner); } diff --git a/src/main/java/subway/screen/ScreenManager.java b/src/main/java/subway/screen/ScreenManager.java index 5f84e7c2e..45733fb1a 100644 --- a/src/main/java/subway/screen/ScreenManager.java +++ b/src/main/java/subway/screen/ScreenManager.java @@ -16,13 +16,13 @@ public static boolean isEmpty() { } public static void show(ScreenModel screen) { - String result = screen.showMenu(); + String result = screen.showScreen(); if (result == DONE) { return; } // todo ์œ ํšจํ•œ ์ž…๋ ฅ์ธ์ง€ ๊ฒ€์ฆํ•œ๋‹ค. - addNextMenuScreen(screen.getNextMenuScreen(result)); + addNextMenuScreen(screen.getNextScreen(result)); } diff --git a/src/main/java/subway/screen/ScreenModel.java b/src/main/java/subway/screen/ScreenModel.java index f77e8fc1f..5edf05eb2 100644 --- a/src/main/java/subway/screen/ScreenModel.java +++ b/src/main/java/subway/screen/ScreenModel.java @@ -1,7 +1,6 @@ package subway.screen; public interface ScreenModel { - public default String showMenu() {return null;} - public default ScreenModel getNextMenuScreen(String input) {return null;} - public default void apply() {} + public default String showScreen() {return "-1";} + public default ScreenModel getNextScreen(String input) {return null;} } diff --git a/src/main/java/subway/screen/SelectCriteriaScreen.java b/src/main/java/subway/screen/SelectCriteriaScreen.java index 5df610e61..80732362f 100644 --- a/src/main/java/subway/screen/SelectCriteriaScreen.java +++ b/src/main/java/subway/screen/SelectCriteriaScreen.java @@ -16,7 +16,7 @@ public SelectCriteriaScreen(Scanner scanner) { } @Override - public String showMenu() { + public String showScreen() { InputView inputView = new InputView(scanner); OutputView.printCriteriaMenu(); @@ -27,4 +27,9 @@ public String showMenu() { return input; } + @Override + public ScreenModel getNextScreen(String input) { + return new FeatureScreen(scanner, input); + } + } From 5f7ea2ca87648b7ed6bb8ee560cfd3e4e61132aa Mon Sep 17 00:00:00 2001 From: soongjamm Date: Sat, 19 Dec 2020 15:43:19 +0900 Subject: [PATCH 07/24] =?UTF-8?q?feat(initilize):=20=EC=B4=88=EA=B8=B0=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EC=84=A4=EC=A0=95=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/java/subway/Application.java | 25 ++++++++++++++++++- src/main/java/subway/domain/Line.java | 9 ++++++- .../java/subway/domain/LineRepository.java | 6 +++++ src/main/java/subway/domain/Section.java | 12 ++++++--- .../java/subway/domain/SectionRepository.java | 9 ++++++- .../java/subway/domain/StationRepository.java | 6 +++++ 7 files changed, 62 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 40a36c58e..00504818f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ## ๊ธฐ๋ณธ ์„ค์ • - ์—ญ, ๋…ธ์„ , ๊ตฌ๊ฐ„์ •๋ณด๋ฅผ ์ดˆ๊ธฐ์„ค์ •ํ•œ๋‹ค. -- ๋…ธ์„ ์€ `์ƒํ–‰์ชฝ์—ญ`, `ํ•˜ํ–‰์ชฝ์—ญ`, `๊ฑฐ๋ฆฌ`, `์‹œ๊ฐ„` ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. +- ๊ตฌ๊ฐ„์€ `๋…ธ์„ `, `์ƒํ–‰์ชฝ์—ญ`, `ํ•˜ํ–‰์ชฝ์—ญ`, `๊ฑฐ๋ฆฌ`, `์‹œ๊ฐ„` ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ``` 1. ์ง€ํ•˜์ฒ ์—ญ์œผ๋กœ ๊ต๋Œ€์—ญ, ๊ฐ•๋‚จ์—ญ, ์—ญ์‚ผ์—ญ, ๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ, ์–‘์žฌ์—ญ, ์–‘์žฌ์‹œ๋ฏผ์˜์ˆฒ์—ญ, ๋งค๋ด‰์—ญ์ด ๋“ฑ๋ก๋˜์–ด ์žˆ๋‹ค. 2. ์ง€ํ•˜์ฒ  ๋…ธ์„ ์œผ๋กœ 2ํ˜ธ์„ , 3ํ˜ธ์„ , ์‹ ๋ถ„๋‹น์„ ์ด ๋“ฑ๋ก๋˜์–ด ์žˆ๋‹ค. diff --git a/src/main/java/subway/Application.java b/src/main/java/subway/Application.java index 7eef3eb1c..0e5a4fcbb 100644 --- a/src/main/java/subway/Application.java +++ b/src/main/java/subway/Application.java @@ -1,15 +1,18 @@ package subway; +import subway.domain.*; import subway.screen.MainScreen; import subway.screen.ScreenManager; import subway.screen.ScreenModel; +import java.util.Arrays; +import java.util.List; import java.util.Scanner; public class Application { public static void main(String[] args) { final Scanner scanner = new Scanner(System.in); - + initialize(); ScreenManager.addNextMenuScreen(new MainScreen(scanner)); while(!ScreenManager.isEmpty()) { @@ -17,4 +20,24 @@ public static void main(String[] args) { ScreenManager.show(nextScreen); } } + + private static void initialize() { + List stations = Arrays.asList(new Station("๊ต๋Œ€์—ญ"), new Station("๊ฐ•๋‚จ์—ญ") + , new Station("์—ญ์‚ผ์—ญ"), new Station("๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ"), new Station("์–‘์žฌ์—ญ") + , new Station("์–‘์žฌ์‹œ๋ฏผ์˜์ˆฒ์—ญ"), new Station("๋งค๋ด‰์—ญ")); + stations.stream().forEach(station -> StationRepository.addStation(station)); + + List lines = Arrays.asList(new Line("2ํ˜ธ์„ ").addTerminus("๊ต๋Œ€์—ญ", "์—ญ์‚ผ์—ญ") + , new Line("3ํ˜ธ์„ ").addTerminus("๊ต๋Œ€์—ญ", "๋งค๋ด‰์—ญ") + , new Line("์‹ ๋ถ„๋‹น์„ ").addTerminus("๊ฐ•๋‚จ์—ญ", "์–‘์žฌ์‹œ๋ฏผ์˜์ˆฒ์—ญ")); + lines.stream().forEach(line -> LineRepository.addLine(line)); + + List
sections = Arrays.asList(new Section("2ํ˜ธ์„ ", "๊ต๋Œ€์—ญ", "๊ฐ•๋‚จ์—ญ", 2, 3) + , new Section("2ํ˜ธ์„ ", "๊ฐ•๋‚จ์—ญ", "์—ญ์‚ผ์—ญ", 2, 3) + , new Section("3ํ˜ธ์„ ", "๊ต๋Œ€์—ญ", "๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ", 3, 2) + , new Section("3ํ˜ธ์„ ", "๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ", "์–‘์žฌ์—ญ", 6, 5) + , new Section("3ํ˜ธ์„ ", "์–‘์žฌ์—ญ", "๋งค๋ด‰์—ญ", 1, 1)); + sections.stream().forEach(section -> SectionRepository.addSection(section)); + + } } diff --git a/src/main/java/subway/domain/Line.java b/src/main/java/subway/domain/Line.java index f4d738d5a..256f392dc 100644 --- a/src/main/java/subway/domain/Line.java +++ b/src/main/java/subway/domain/Line.java @@ -1,7 +1,10 @@ package subway.domain; +import java.util.LinkedList; + public class Line { private String name; + private LinkedList line = new LinkedList<>(); public Line(String name) { this.name = name; @@ -11,5 +14,9 @@ public String getName() { return name; } - // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ + public Line addTerminus(String upBoundTerminus, String downBoundTerminus) { + line.addFirst(StationRepository.findStation(upBoundTerminus)); + line.addLast(StationRepository.findStation(downBoundTerminus)); + return this; + } } diff --git a/src/main/java/subway/domain/LineRepository.java b/src/main/java/subway/domain/LineRepository.java index 2c4a723c9..69bfd17cc 100644 --- a/src/main/java/subway/domain/LineRepository.java +++ b/src/main/java/subway/domain/LineRepository.java @@ -23,4 +23,10 @@ public static boolean deleteLineByName(String name) { public static void deleteAll() { lines.clear(); } + + public static Line findLine(String name) { + return lines.stream() + .filter(line -> line.getName().equals(name)) + .findFirst().orElseThrow(() -> new IllegalArgumentException("[ERROR] ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๋…ธ์„ ")); + } } diff --git a/src/main/java/subway/domain/Section.java b/src/main/java/subway/domain/Section.java index 3ea378c25..170b00cc5 100644 --- a/src/main/java/subway/domain/Section.java +++ b/src/main/java/subway/domain/Section.java @@ -1,14 +1,20 @@ package subway.domain; public class Section { + private Line line; private Station departureStation; private Station arriavalStation; private int distance; private int costTime; - public Section(Station departureStation, Station arriavalStation, int distance, int costTime) { - this.departureStation = departureStation; - this.arriavalStation = arriavalStation; + public Section(String lineName, String departureName, String arrivalName, int distance, int costTime) { + Line line = LineRepository.findLine(lineName); + Station departure = StationRepository.findStation(departureName); + Station arrival = StationRepository.findStation(arrivalName); + + this.line = line; + this.departureStation = departure; + this.arriavalStation = arrival; this.distance = distance; this.costTime = costTime; } diff --git a/src/main/java/subway/domain/SectionRepository.java b/src/main/java/subway/domain/SectionRepository.java index 856ae488b..1f7ee1ce4 100644 --- a/src/main/java/subway/domain/SectionRepository.java +++ b/src/main/java/subway/domain/SectionRepository.java @@ -1,7 +1,14 @@ package subway.domain; +import java.util.ArrayList; +import java.util.List; + public class SectionRepository { - public void addSection() { + static List
sections = new ArrayList<>(); + + public static void addSection(Section section) { + sections.add(section); } + } diff --git a/src/main/java/subway/domain/StationRepository.java b/src/main/java/subway/domain/StationRepository.java index 8ed9d103f..a475e9e85 100644 --- a/src/main/java/subway/domain/StationRepository.java +++ b/src/main/java/subway/domain/StationRepository.java @@ -23,4 +23,10 @@ public static boolean deleteStation(String name) { public static void deleteAll() { stations.clear(); } + + public static Station findStation(String name) { + return stations.stream() + .filter(station -> station.getName().equals(name)) + .findFirst().orElseThrow(() -> new IllegalArgumentException(("[ERROR] ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์—ญ"))); + } } From e7d79eb9ad8342110ff484a0ede79ce470a8178d Mon Sep 17 00:00:00 2001 From: soongjamm Date: Sat, 19 Dec 2020 15:48:49 +0900 Subject: [PATCH 08/24] =?UTF-8?q?docs(readme.md):=20=EA=B5=AC=ED=98=84=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EB=AA=A9=EB=A1=9D=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=EC=99=80=20=ED=95=84=EC=9A=94=20=EA=B0=9D=EC=B2=B4=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 00504818f..94d0b1508 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ ``` ## ๊ตฌํ˜„ ๊ธฐ๋Šฅ ๋ชฉ๋ก +- ์ดˆ๊ธฐ ์„ค์ •์„ ์œ„ํ•ด ์—ญ, ๋…ธ์„ , ๊ตฌ๊ฐ„ ์ •๋ณด๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค. - ๋ฉ”์ธ ํ™”๋ฉด์—์„œ ๋ฉ”๋‰ด๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. - ๋ฉ”์ธ ํ™”๋ฉด์—์„œ ๊ฒฝ๋กœ ์กฐํšŒ์™€ ์ข…๋ฃŒ์ค‘ ์ž…๋ ฅ์„ ๋ฐ›๋Š”๋‹ค. (1: ๊ฒฝ๋กœ์กฐํšŒ, Q: ์ข…๋ฃŒ) - ๊ฒฝ๋กœ ๊ธฐ์ค€ ํ™”๋ฉด์—์„œ ๋ฉ”๋‰ด๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. @@ -35,6 +36,9 @@ ## ๊ฐ์ฒด - ํ™”๋ฉด ๊ด€๋ฆฌ ๊ฐ์ฒด +- ๋ฉ”์ธ ํ™”๋ฉด +- ๊ฒฝ๋กœ ๊ธฐ์ค€ ์„ ํƒ ํ™”๋ฉด +- ๊ธฐ๋Šฅ ํ™”๋ฉด - ์ถœ๋ ฅ - ์ž…๋ ฅ - ์—ญ From 921666cffa60032758d4387fa201363c98ce545d Mon Sep 17 00:00:00 2001 From: soongjamm Date: Sat, 19 Dec 2020 17:37:56 +0900 Subject: [PATCH 09/24] =?UTF-8?q?feat(ShortestPath):=20=EC=B5=9C=EB=8B=A8?= =?UTF-8?q?=EA=B1=B0=EB=A6=AC=20=EA=B3=84=EC=82=B0=EC=9D=84=20=EC=9C=84?= =?UTF-8?q?=ED=95=B4=20Section=EA=B3=BC=20SectionRepository=EC=97=90=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/domain/Line.java | 6 +++- src/main/java/subway/domain/Section.java | 21 +++++++++--- .../java/subway/domain/SectionRepository.java | 34 +++++++++++++++++++ src/main/java/subway/menu/Menu.java | 10 ++++-- .../java/subway/screen/FeatureScreen.java | 10 +++++- src/main/java/subway/view/InputView.java | 12 ++++++- 6 files changed, 84 insertions(+), 9 deletions(-) diff --git a/src/main/java/subway/domain/Line.java b/src/main/java/subway/domain/Line.java index 256f392dc..3c2ef9771 100644 --- a/src/main/java/subway/domain/Line.java +++ b/src/main/java/subway/domain/Line.java @@ -3,8 +3,8 @@ import java.util.LinkedList; public class Line { + private static LinkedList line = new LinkedList<>(); private String name; - private LinkedList line = new LinkedList<>(); public Line(String name) { this.name = name; @@ -14,6 +14,10 @@ public String getName() { return name; } + public void addSection(int sequence, Station station) { + line.add(sequence, station); + } + public Line addTerminus(String upBoundTerminus, String downBoundTerminus) { line.addFirst(StationRepository.findStation(upBoundTerminus)); line.addLast(StationRepository.findStation(downBoundTerminus)); diff --git a/src/main/java/subway/domain/Section.java b/src/main/java/subway/domain/Section.java index 170b00cc5..f2a504532 100644 --- a/src/main/java/subway/domain/Section.java +++ b/src/main/java/subway/domain/Section.java @@ -1,9 +1,11 @@ package subway.domain; public class Section { + private Line line; - private Station departureStation; - private Station arriavalStation; + + private Station departure; + private Station arrival; private int distance; private int costTime; @@ -13,10 +15,21 @@ public Section(String lineName, String departureName, String arrivalName, int di Station arrival = StationRepository.findStation(arrivalName); this.line = line; - this.departureStation = departure; - this.arriavalStation = arrival; + this.departure = departure; + this.arrival = arrival; this.distance = distance; this.costTime = costTime; } + public Station getDeparture() { + return departure; + } + + public Station getArrival() { + return arrival; + } + + public int getCostTime() { + return costTime; + } } diff --git a/src/main/java/subway/domain/SectionRepository.java b/src/main/java/subway/domain/SectionRepository.java index 1f7ee1ce4..fe0247a5c 100644 --- a/src/main/java/subway/domain/SectionRepository.java +++ b/src/main/java/subway/domain/SectionRepository.java @@ -1,14 +1,48 @@ package subway.domain; +import org.jgrapht.alg.shortestpath.DijkstraShortestPath; +import org.jgrapht.graph.DefaultWeightedEdge; +import org.jgrapht.graph.WeightedMultigraph; + import java.util.ArrayList; import java.util.List; public class SectionRepository { + static WeightedMultigraph graph = new WeightedMultigraph(DefaultWeightedEdge.class); static List
sections = new ArrayList<>(); + public static List
sections() { + return sections; + } + public static void addSection(Section section) { sections.add(section); + addVertex(section.getDeparture(), section.getArrival()); + addWeight(section.getDeparture(), section.getArrival(), section.getCostTime()); + } + + private static void addWeight(Station departure, Station arrival, int costTime) { + if (!graph.containsEdge(graph.addEdge(departure.getName(), arrival.getName()))) { + graph.setEdgeWeight(graph.addEdge(departure.getName(), arrival.getName()), costTime); + } + } + + private static void addVertex(Station departure, Station arrival) { + if (!graph.containsVertex(departure.getName())) { + graph.addVertex(departure.getName()); + } + if (!graph.containsVertex(arrival.getName())) { + graph.addVertex(arrival.getName()); + } + } + + public static void findShortestPath(String departure, String destination) { + int shortestDistance = 0; + + DijkstraShortestPath dijkstraShortestPath = new DijkstraShortestPath(graph); + List shortestPath = dijkstraShortestPath.getPath(departure, destination).getVertexList(); + } } diff --git a/src/main/java/subway/menu/Menu.java b/src/main/java/subway/menu/Menu.java index a7c979808..0e126d8ed 100644 --- a/src/main/java/subway/menu/Menu.java +++ b/src/main/java/subway/menu/Menu.java @@ -1,10 +1,16 @@ package subway.menu; +import org.jgrapht.alg.shortestpath.DijkstraShortestPath; +import org.jgrapht.graph.DefaultWeightedEdge; +import org.jgrapht.graph.WeightedMultigraph; +import subway.domain.SectionRepository; + +import java.util.List; + public class Menu { public enum Main { ROUTE_INQUIRY("1", "๊ฒฝ๋กœ์กฐํšŒ"), - QUIT("Q", "์ข…๋ฃŒ"), - ; + QUIT("Q", "์ข…๋ฃŒ"); private String code; private String korean; diff --git a/src/main/java/subway/screen/FeatureScreen.java b/src/main/java/subway/screen/FeatureScreen.java index fde51e6d3..98b985b32 100644 --- a/src/main/java/subway/screen/FeatureScreen.java +++ b/src/main/java/subway/screen/FeatureScreen.java @@ -1,5 +1,8 @@ package subway.screen; +import subway.domain.SectionRepository; +import subway.view.InputView; + import java.util.Scanner; public class FeatureScreen implements ScreenModel { @@ -14,7 +17,12 @@ public FeatureScreen(Scanner scanner, String input) { @Override public String showScreen() { - System.out.println("์ตœ๋‹จ๊ฑฐ๋ฆฌ๋‚˜ ์ตœ์†Œ์‹œ๊ฐ„ ์‹คํ–‰"); + InputView inputView = new InputView(scanner); + + String departure = inputView.enterDeparture(); + String arrival = inputView.enterArrival(); + SectionRepository.findShortestPath(departure, arrival); + return "-1"; } diff --git a/src/main/java/subway/view/InputView.java b/src/main/java/subway/view/InputView.java index 5ef69f9f7..5a0f624dd 100644 --- a/src/main/java/subway/view/InputView.java +++ b/src/main/java/subway/view/InputView.java @@ -11,7 +11,7 @@ public InputView(Scanner scanner) { } public String enterFeature() { - System.out.println("์›ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์„ ํƒํ•˜์„ธ์š”."); + System.out.println("## ์›ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์„ ํƒํ•˜์„ธ์š”."); return scanner.nextLine(); } @@ -26,4 +26,14 @@ public void enterDepartualStation() { public void enterArrivalStation() { } + + public String enterDeparture() { + System.out.println("## ์ถœ๋ฐœ์—ญ์„ ์ž…๋ ฅํ•˜์„ธ์š”."); + return scanner.nextLine(); + } + + public String enterArrival() { + System.out.println("## ๋„์ฐฉ์—ญ์„ ์ž…๋ ฅํ•˜์„ธ์š”."); + return scanner.nextLine(); + } } From 9bdbfc3328e644b30ca6b58a0c7483accc672612 Mon Sep 17 00:00:00 2001 From: soongjamm Date: Sat, 19 Dec 2020 17:58:20 +0900 Subject: [PATCH 10/24] =?UTF-8?q?etc:=20=EB=AF=B8=EC=99=84=EC=84=B1=20?= =?UTF-8?q?=EC=8B=9C=ED=97=98=20=EC=8B=9C=EA=B0=84=EC=9D=B4=20=EB=8B=A4?= =?UTF-8?q?=EB=90=98=EC=96=B4=EC=84=9C=20=ED=98=84=EC=9E=AC=20=EC=B5=9C?= =?UTF-8?q?=EB=8B=A8=EA=B1=B0=EB=A6=AC=EB=A1=9C=20=EA=B8=B8=EC=B0=BE?= =?UTF-8?q?=EA=B8=B0=20=EA=B5=AC=ED=98=84=20=EC=A4=91=20=EC=BB=A4=EB=B0=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/domain/Section.java | 12 ++++++++++++ src/main/java/subway/domain/SectionRepository.java | 8 ++++++-- src/main/java/subway/screen/FeatureScreen.java | 4 +++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/java/subway/domain/Section.java b/src/main/java/subway/domain/Section.java index f2a504532..b45bfb86a 100644 --- a/src/main/java/subway/domain/Section.java +++ b/src/main/java/subway/domain/Section.java @@ -21,6 +21,18 @@ public Section(String lineName, String departureName, String arrivalName, int di this.costTime = costTime; } + public boolean hasStation(String station1, String station2) { + if ((station1.equals(arrival.getName()) || station2.equals(arrival.getName())) + && (station1.equals(departure.getName()) || station2.equals(departure.getName()))) { + return true; + } + return false; + } + + public int getDistance() { + return distance; + } + public Station getDeparture() { return departure; } diff --git a/src/main/java/subway/domain/SectionRepository.java b/src/main/java/subway/domain/SectionRepository.java index fe0247a5c..1d92ee180 100644 --- a/src/main/java/subway/domain/SectionRepository.java +++ b/src/main/java/subway/domain/SectionRepository.java @@ -37,12 +37,16 @@ private static void addVertex(Station departure, Station arrival) { } } - public static void findShortestPath(String departure, String destination) { - int shortestDistance = 0; + public static int findShortestPath(String departure, String destination) { DijkstraShortestPath dijkstraShortestPath = new DijkstraShortestPath(graph); List shortestPath = dijkstraShortestPath.getPath(departure, destination).getVertexList(); + return (int) sections.stream() + .filter(section -> section.hasStation(departure, destination)) + .mapToInt(Section::getDistance) + .sum(); + } } diff --git a/src/main/java/subway/screen/FeatureScreen.java b/src/main/java/subway/screen/FeatureScreen.java index 98b985b32..3e4857ca1 100644 --- a/src/main/java/subway/screen/FeatureScreen.java +++ b/src/main/java/subway/screen/FeatureScreen.java @@ -18,10 +18,12 @@ public FeatureScreen(Scanner scanner, String input) { @Override public String showScreen() { InputView inputView = new InputView(scanner); + int shortestResult = 0; String departure = inputView.enterDeparture(); String arrival = inputView.enterArrival(); - SectionRepository.findShortestPath(departure, arrival); + shortestResult = SectionRepository.findShortestPath(departure, arrival); + System.out.println(shortestResult); return "-1"; } From f2b5842ea9d0be9493e190e56fbd1e4c5160e954 Mon Sep 17 00:00:00 2001 From: soongjamm Date: Sat, 19 Dec 2020 18:25:37 +0900 Subject: [PATCH 11/24] Update README.md --- README.md | 145 +++++++++++++++++------------------------------------- 1 file changed, 45 insertions(+), 100 deletions(-) diff --git a/README.md b/README.md index 618018a7c..3e1fea825 100644 --- a/README.md +++ b/README.md @@ -1,104 +1,49 @@ -# ์ง€ํ•˜์ฒ  ๋…ธ์„ ๋„ ๋ฏธ์…˜ -- ์ง€ํ•˜์ฒ  ์—ญ๊ณผ ๋…ธ์„ ์„ ๊ด€๋ฆฌํ•˜๋Š” ์ง€ํ•˜์ฒ  ๋…ธ์„ ๋„ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•œ๋‹ค. +# ์ง€ํ•˜์ฒ  ๋…ธ์„ ๋„ ๊ฒฝ๋กœ ์กฐํšŒ ๋ฏธ์…˜ +- ๋“ฑ๋ก๋œ ์ง€ํ•˜์ฒ  ๋…ธ์„ ๋„์—์„œ ๊ฒฝ๋กœ๋ฅผ ์กฐํšŒํ•˜๋Š” ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•œ๋‹ค.
-## ๊ตฌํ˜„ ๊ธฐ๋Šฅ ๋ชฉ๋ก -- [์ž…๋ ฅ](#๊ฐ๊ฐ์˜-๊ธฐ๋Šฅ-์„ ํƒ-ํ™”๋ฉด์—์„œ์˜-์ž…๋ ฅ) -- [์„ธ๋ถ€๊ธฐ๋Šฅ](#์„ธ๋ถ€-๊ธฐ๋Šฅ) - -### ๊ฐ๊ฐ์˜ ๊ธฐ๋Šฅ ์„ ํƒ ํ™”๋ฉด์—์„œ์˜ ์ž…๋ ฅ -- ๊ฐ ํ™”๋ฉด์—์„œ ์–ด๋–ค ๊ธฐ๋Šฅ์„ ์ˆ˜ํ–‰ํ• ์ง€ ๋ฌธ์ž๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. - - ๋ฉ”์ธ, ์—ญ ๊ด€๋ฆฌ, ๋…ธ์„  ๊ด€๋ฆฌ, ๊ตฌ๊ฐ„ ๊ด€๋ฆฌ ํ™”๋ฉด์ด ์žˆ๋‹ค. -- ์ž…๋ ฅ๋ฐ›์€ ๊ฐ’์ด ๊ฐ ํ™”๋ฉด์˜ `์ž…๋ ฅ ํ—ˆ์šฉ ๋ฌธ์ž` ์— ํฌํ•จ๋˜๋Š”์ง€ ๊ฒ€์ฆํ•œ๋‹ค. -- ์ž…๋ ฅ์— ๋”ฐ๋ผ ํ™”๋ฉด์„ ์ด๋™ํ•œ๋‹ค. - -- `์˜ˆ์™ธ ์ฒ˜๋ฆฌ` - - `์ž…๋ ฅ ํ—ˆ์šฉ ๋ฌธ์ž`์™ธ์˜ ์ž…๋ ฅ์€ ๋Œ€ํ•ด ์—๋Ÿฌ๋ฅผ ์ถœ๋ ฅ - -- `์ž…๋ ฅ ํ—ˆ์šฉ ๋ฌธ์ž` - - **๋ฉ”์ธ ํ™”๋ฉด** - - `1` : ์—ญ ๊ด€๋ฆฌ ํ™”๋ฉด์œผ๋กœ ์ด๋™ํ•œ๋‹ค. - - `2` : ๋…ธ์„  ๊ด€๋ฆฌ ํ™”๋ฉด์œผ๋กœ ์ด๋™ํ•œ๋‹ค. - - `3` : ๊ตฌ๊ฐ„ ๊ด€๋ฆฌ ํ™”๋ฉด์œผ๋กœ ์ด๋™ํ•œ๋‹ค. - - `4` : ์ง€ํ•˜์ฒ  ๋…ธ์„ ๋„ ์ถœ๋ ฅํ•œ๋‹ค. - - `Q` : ํ”„๋กœ๊ทธ๋žจ์„ ์ข…๋ฃŒํ•œ๋‹ค. - - - **์—ญ ๊ด€๋ฆฌ ํ™”๋ฉด** - - `1` : ์—ญ ๋“ฑ๋ก ํ™”๋ฉด์œผ๋กœ ์ด๋™ํ•œ๋‹ค. - - `2` : ์—ญ ์‚ญ์ œ ํ™”๋ฉด์œผ๋กœ ์ด๋™ํ•œ๋‹ค. - - `3` : ์—ญ ์กฐํšŒ ํ™”๋ฉด์œผ๋กœ ์ด๋™ํ•œ๋‹ค. - - `B` : ๋ฉ”์ธ ํ™”๋ฉด์œผ๋กœ ์ด๋™ํ•œ๋‹ค. - - - **๋…ธ์„  ๊ด€๋ฆฌ ํ™”๋ฉด** - - `1` : ๋…ธ์„  ๋“ฑ๋ก ํ™”๋ฉด์œผ๋กœ ์ด๋™ํ•œ๋‹ค. - - `2` : ๋…ธ์„  ์‚ญ์ œ ํ™”๋ฉด์œผ๋กœ ์ด๋™ํ•œ๋‹ค. - - `3` : ๋…ธ์„  ์กฐํšŒ ํ™”๋ฉด์œผ๋กœ ์ด๋™ํ•œ๋‹ค. - - `B` : ๋ฉ”์ธ ํ™”๋ฉด์œผ๋กœ ์ด๋™ํ•œ๋‹ค. - - - **๊ตฌ๊ฐ„ ๊ด€๋ฆฌ ํ™”๋ฉด** - - `1` : ๋…ธ์„  ๋“ฑ๋ก ํ™”๋ฉด์œผ๋กœ ์ด๋™ํ•œ๋‹ค. - - `2` : ๋…ธ์„  ์‚ญ์ œ ํ™”๋ฉด์œผ๋กœ ์ด๋™ํ•œ๋‹ค. - - `B` : ๋ฉ”์ธ ํ™”๋ฉด์œผ๋กœ ์ด๋™ํ•œ๋‹ค. - -
+## ๊ธฐ๋ณธ ์„ค์ • +- ์—ญ, ๋…ธ์„ , ๊ตฌ๊ฐ„์ •๋ณด๋ฅผ ์ดˆ๊ธฐ์„ค์ •ํ•œ๋‹ค. +- ๊ตฌ๊ฐ„์€ `๋…ธ์„ `, `์ƒํ–‰์ชฝ์—ญ`, `ํ•˜ํ–‰์ชฝ์—ญ`, `๊ฑฐ๋ฆฌ`, `์‹œ๊ฐ„` ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. +``` +1. ์ง€ํ•˜์ฒ ์—ญ์œผ๋กœ ๊ต๋Œ€์—ญ, ๊ฐ•๋‚จ์—ญ, ์—ญ์‚ผ์—ญ, ๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ, ์–‘์žฌ์—ญ, ์–‘์žฌ์‹œ๋ฏผ์˜์ˆฒ์—ญ, ๋งค๋ด‰์—ญ์ด ๋“ฑ๋ก๋˜์–ด ์žˆ๋‹ค. +2. ์ง€ํ•˜์ฒ  ๋…ธ์„ ์œผ๋กœ 2ํ˜ธ์„ , 3ํ˜ธ์„ , ์‹ ๋ถ„๋‹น์„ ์ด ๋“ฑ๋ก๋˜์–ด ์žˆ๋‹ค. +3. ๋…ธ์„ ์— ์—ญ์ด ์•„๋ž˜์™€ ๊ฐ™์ด ๋“ฑ๋ก๋˜์–ด ์žˆ๋‹ค.(์™ผ์ชฝ ๋์ด ์ƒํ–‰ ์ข…์ ) + - 2ํ˜ธ์„ : ๊ต๋Œ€์—ญ - ( 2km / 3๋ถ„ ) - ๊ฐ•๋‚จ์—ญ - ( 2km / 3๋ถ„ ) - ์—ญ์‚ผ์—ญ + - 3ํ˜ธ์„ : ๊ต๋Œ€์—ญ - ( 3km / 2๋ถ„ ) - ๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ - ( 6km / 5๋ถ„ ) - ์–‘์žฌ์—ญ - ( 1km / 1๋ถ„ ) - ๋งค๋ด‰์—ญ + - ์‹ ๋ถ„๋‹น์„ : ๊ฐ•๋‚จ์—ญ - ( 2km / 8๋ถ„ ) - ์–‘์žฌ์—ญ - ( 10km / 3๋ถ„ ) - ์–‘์žฌ์‹œ๋ฏผ์˜์ˆฒ์—ญ +``` -### ์„ธ๋ถ€ ๊ธฐ๋Šฅ -### ์ง€ํ•˜์ฒ  ์—ญ ๊ด€๋ จ ๊ธฐ๋Šฅ -- ์—ญ ๋“ฑ๋ก, ์—ญ ์‚ญ์ œ, ์—ญ ์กฐํšŒ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค. -- (๋“ฑ๋ก/์‚ญ์ œ) ์—ญ ์ด๋ฆ„์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. -- (๋“ฑ๋ก/์‚ญ์ œ) ์ž…๋ ฅ์ด ์˜ฌ๋ฐ”๋ฅธ์ง€ ๊ฒ€์ฆํ•ด์•ผ ํ•œ๋‹ค. -- (๋“ฑ๋ก/์‚ญ์ œ) ์ž…๋ ฅ๊ณผ ๋™์ผํ•œ ์ด๋ฆ„์˜ ์—ญ์ด ์กด์žฌํ•˜๋Š”์ง€ ๊ฒ€์‚ฌํ•œ๋‹ค. - - (๋“ฑ๋ก) ์ž…๋ ฅ์ด ์—ญ ๋ชฉ๋ก์— ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ๋ชฉ๋ก์— ์ถ”๊ฐ€ํ•œ๋‹ค. - - (์‚ญ์ œ) ์ž…๋ ฅ์ด ์—ญ ๋ชฉ๋ก์— ์กด์žฌํ•œ๋‹ค๋ฉด ๋ชฉ๋ก์—์„œ ์‚ญ์ œํ•œ๋‹ค. -- (์กฐํšŒ) ๋ชจ๋“  ์—ญ ์ด๋ฆ„์„ ์ถœ๋ ฅํ•œ๋‹ค. - -- `์ž…๋ ฅ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ` - - ์•ž/๋’ค ๊ณต๋ฐฑ์„ ์ œ์™ธํ•˜๊ณ  ์ž…๋ ฅ์ด 2๊ธ€์ž ๋ฏธ๋งŒ์ธ ๊ฒฝ์šฐ - - ์ž…๋ ฅ์— ์ž์Œ/๋ชจ์Œ์œผ๋กœ ๊ตฌ์„ฑ๋œ ํ•œ๊ธ€, ์˜์–ด, ์ˆซ์ž ์™ธ์˜ ๋ฌธ์ž๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ - - ์ด๋ฆ„์ด `์—ญ`์œผ๋กœ ๋๋‚˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ - - (๋“ฑ๋ก) ์ž…๋ ฅ์ด ๋ชฉ๋ก์— ์ด๋ฏธ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ - - (์‚ญ์ œ) ์ž…๋ ฅ์ด ๋ชฉ๋ก์— ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ - - -### ๋…ธ์„  ๊ด€๋ จ ๊ธฐ๋Šฅ -- ๋…ธ์„  ๋“ฑ๋ก, ๋…ธ์„  ์‚ญ์ œ, ๋…ธ์„  ์กฐํšŒ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค. -- (๋“ฑ๋ก/์‚ญ์ œ) ๋…ธ์„  ์ด๋ฆ„์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. -- (๋“ฑ๋ก/์‚ญ์ œ) ๋…ธ์„  ๋“ฑ๋ก/์‚ญ์ œ์˜ ์ž…๋ ฅ์ด 2๊ธ€์ž ์ด์ƒ์ธ์ง€ ๊ฒ€์ฆํ•ด์•ผ ํ•œ๋‹ค. -- (๋“ฑ๋ก) ์ƒํ–‰ ์ข…์ ์—ญ๊ณผ ํ•˜ํ–‰ ์ข…์ ์—ญ์„ ์ž…๋ ฅ๋ฐ›์•„์•ผ ํ•œ๋‹ค. - - ์ƒํ–‰, ํ•˜ํ–‰ ์ข…์ ์—ญ ์ž…๋ ฅ์ด ์—ญ ๋ชฉ๋ก์— ์กด์žฌํ•˜๋Š”์ง€ ๊ฒ€์‚ฌํ•œ๋‹ค. -- (๋“ฑ๋ก/์‚ญ์ œ) ์ž…๋ ฅ๊ณผ ๋™์ผํ•œ ์ด๋ฆ„์˜ ๋…ธ์„ ์ด ์กด์žฌํ•˜๋Š”์ง€ ๊ฒ€์‚ฌํ•œ๋‹ค. - - ๋“ฑ๋ก์˜ ๊ฒฝ์šฐ ๋…ธ์„  ๋ชฉ๋ก์— ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ๋ชฉ๋ก์— ๋“ฑ๋กํ•œ๋‹ค. - - ์‚ญ์ œ์˜ ๊ฒฝ์šฐ ๋…ธ์„  ๋ชฉ๋ก์— ์กด์žฌํ•œ๋‹ค๋ฉด ๋ชฉ๋ก์—์„œ ์‚ญ์ œํ•œ๋‹ค. -- (์กฐํšŒ) ๋ชจ๋“  ๋…ธ์„  ์ด๋ฆ„์„ ์ถœ๋ ฅํ•œ๋‹ค. -- (๋“ฑ๋ก) ์ƒํ–‰๊ณผ ํ•˜ํ–‰ ์ข…์ ์—ญ์ด ๊ฐ™์€ ๊ฒฝ์šฐ ์ˆœํ™˜์„ ์ด๋ฏ€๋กœ ๊ฐ€๋Šฅํ•˜๋‹ค. - -- `์˜ˆ์™ธ ์ฒ˜๋ฆฌ` - - ์•ž/๋’ค ๊ณต๋ฐฑ์„ ์ œ์™ธํ•˜๊ณ  ์ž…๋ ฅ์ด 2๊ธ€์ž ๋ฏธ๋งŒ์ธ ๊ฒฝ์šฐ - - ์ž…๋ ฅ์— ์ž์Œ/๋ชจ์Œ์œผ๋กœ ๊ตฌ์„ฑ๋œ ํ•œ๊ธ€, ์˜์–ด, ์ˆซ์ž ์™ธ์˜ ๋ฌธ์ž๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ - - (๋“ฑ๋ก) ๋…ธ์„ ๋ช… ์ž…๋ ฅ์ด ๋ชฉ๋ก์— ์ด๋ฏธ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ - - (๋“ฑ๋ก) ์ƒํ–‰์ด๋‚˜ ํ•˜ํ–‰ ์ข…์ ์—ญ์ด ์—ญ ๋ชฉ๋ก์— ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ - - (์‚ญ์ œ) ๋…ธ์„ ๋ช… ์ž…๋ ฅ์ด ๋ชฉ๋ก์— ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ - -### ๊ตฌ๊ฐ„ ๊ด€๋ จ ๊ธฐ๋Šฅ -- ๋…ธ์„ ์— ์—ญ์„ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜, ๋…ธ์„ ์— ๋“ฑ๋ก๋œ ์—ญ ์ œ๊ฑฐ๊ฐ€ ๊ฐ€๋Šฅํ•˜๊ณ , ๋…ธ์„ ๋„๋ฅผ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ๋‹ค. -- ์—ญ๊ณผ ์—ญ ์‚ฌ์ด์— ๊ตฌ๊ฐ„์ด ์ถ”๊ฐ€ ๋  ์ˆ˜ ์žˆ๋‹ค. -- ํ•˜๋‚˜์˜ ์—ญ์€ ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋…ธ์„ ์— ํฌํ•จ๋  ์ˆ˜ ์žˆ๋‹ค. -- (์ถ”๊ฐ€) ๋…ธ์„  ์ด๋ฆ„์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. - - ๋…ธ์„  ์ด๋ฆ„์ด ๋…ธ์„  ๋ชฉ๋ก์— ์žˆ๋Š”์ง€ ๊ฒ€์‚ฌํ•œ๋‹ค. -- (์ถ”๊ฐ€) ์—ญ ์ด๋ฆ„์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. - - ์—ญ ์ด๋ฆ„์ด ์—ญ ๋ชฉ๋ก์— ์žˆ๋Š”์ง€ ๊ฒ€์‚ฌํ•œ๋‹ค. -- (์ถ”๊ฐ€) ์ถ”๊ฐ€ํ•˜๋ ค๋Š” ๋…ธ์„ ์˜ ์ˆœ์„œ๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. (1๋ถ€ํ„ฐ ์‹œ์ž‘ -> 1์€ ์ƒํ–‰์ข…์ ์—ญ ๋‹ค์Œ์— ์ถ”๊ฐ€) - - ์ž…๋ ฅ์ด ์ •์ˆ˜ 1๋ถ€ํ„ฐ (๋…ธ์„ ์˜ ๊ธธ์ด-1) ์ธ์ง€ ๊ฒ€์‚ฌํ•œ๋‹ค. -- (์ถ”๊ฐ€) ๋…ธ์„ ์— ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์—ญ์ด๋ผ๋ฉด n๋ฒˆ์งธ์— ์—ญ์„ ์ถ”๊ฐ€ํ•œ๋‹ค. -- (์‚ญ์ œ) ๋…ธ์„  ์ด๋ฆ„์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. - - ๋…ธ์„  ์ด๋ฆ„์ด ๋…ธ์„  ๋ชฉ๋ก์— ์žˆ๋Š”์ง€ ๊ฒ€์‚ฌํ•œ๋‹ค. -- (์‚ญ์ œ) ์—ญ ์ด๋ฆ„์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. - - ์—ญ ์ด๋ฆ„์ด ํ•ด๋‹น ๋…ธ์„ ์— ํฌํ•จ๋˜์–ด ์žˆ๋Š”์ง€ ๊ฒ€์‚ฌํ•œ๋‹ค. -- (์‚ญ์ œ) ๋…ธ์„ ์—์„œ ์—ญ์„ ์‚ญ์ œํ•œ๋‹ค. ์‚ญ์ œํ•œ ์—ญ์ด ์ข…์ ์ด๋ฉด ๊ทธ ๋‹ค์Œ ์—ญ์ด ์ข…์ ์ด ๋œ๋‹ค. (ํ•˜ํ–‰ ์ข…์ ์—ญ์ด๋ฉด ๊ทธ ์ „ ์—ญ์ด ์ข…์ ์ด ๋œ๋‹ค.) -- (์กฐํšŒ) ๋ฉ”์ธ ๋ฉ”๋‰ด์—์„œ `์ง€ํ•˜์ฒ  ๋…ธ์„ ๋„ ์ถœ๋ ฅ`์„ ํ†ตํ•ด ๊ฐ€๋Šฅํ•˜๋ฉฐ ๋ชจ๋“  ๋…ธ์„ ์˜ ์ƒํ–‰~ํ•˜ํ–‰ ์ข…์ ์—ญ๊นŒ์ง€ ์—ฐ๊ฒฐ๋œ ์ˆœ์„œ๋Œ€๋กœ ์กฐํšŒ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค. - -- `์˜ˆ์™ธ ์ฒ˜๋ฆฌ` - - ์—ญ์ด๋‚˜ ๋…ธ์„ ์˜ ์ด๋ฆ„์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ - - (๋“ฑ๋ก) ๋…ธ์„ ์— ๋™์ผํ•œ ์ด๋ฆ„์˜ ์—ญ์ด ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ (๊ฐˆ๋ž˜๊ธธ ๋ฐœ์ƒ ๋ฐฉ์ง€) - - (์‚ญ์ œ) ๋…ธ์„ ์— ํฌํ•จ๋œ ์—ญ์ด 2๊ฐœ์ธ ๊ฒฝ์šฐ +## ๊ตฌํ˜„ ๊ธฐ๋Šฅ ๋ชฉ๋ก +- ์ดˆ๊ธฐ ์„ค์ •์„ ์œ„ํ•ด ์—ญ, ๋…ธ์„ , ๊ตฌ๊ฐ„ ์ •๋ณด๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค. +- ๋ฉ”์ธ ํ™”๋ฉด์—์„œ ๋ฉ”๋‰ด๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. +- ๋ฉ”์ธ ํ™”๋ฉด์—์„œ ๊ฒฝ๋กœ ์กฐํšŒ์™€ ์ข…๋ฃŒ์ค‘ ์ž…๋ ฅ์„ ๋ฐ›๋Š”๋‹ค. (1: ๊ฒฝ๋กœ์กฐํšŒ, Q: ์ข…๋ฃŒ) +- ๊ฒฝ๋กœ ๊ธฐ์ค€ ํ™”๋ฉด์—์„œ ๋ฉ”๋‰ด๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. +- ๊ฒฝ๋กœ ๊ธฐ์ค€์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. (1: ์ตœ๋‹จ๊ฑฐ๋ฆฌ, 2: ์ตœ์†Œ์‹œ๊ฐ„) +- ๊ฒฝ๋กœ๋ฅผ ์กฐํšŒํ•œ๋‹ค. + - ์ถœ๋ฐœ์—ญ์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. + - ๋„์ฐฉ์—ญ์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. + - (๊ฒฝ๋กœ ๊ธฐ์ค€) ์ถœ๋ฐœ์—ญ์—์„œ ๋„์ฐฉ์—ญ๊นŒ์ง€์˜ ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ์ตœ๋‹จ ๊ฑฐ๋ฆฌ์ธ ๊ฒฝ๋กœ๋ฅผ ๊ณ„์‚ฐํ•œ๋‹ค. + - (์‹œ๊ฐ„ ๊ธฐ์ค€) ์ถœ๋ฐœ์—ญ์—์„œ ๋„์ฐฉ์—ญ๊นŒ์ง€์˜ ์ด ์†Œ์š”์‹œ๊ฐ„์ด ๊ฐ€์žฅ ์งง์€ ๊ฒฝ๋กœ๋ฅผ ๊ณ„์‚ฐํ•œ๋‹ค. + - ์ฐพ์•„๋‚ธ ๊ฒฝ๋กœ์˜ ๊ฑฐ๋ฆฌ์™€ ์†Œ์š”์‹œ๊ฐ„์„ ์ถœ๋ ฅํ•œ๋‹ค. +- ์ข…๋ฃŒํ•œ๋‹ค. + +`์˜ˆ์™ธ์ฒ˜๋ฆฌ` +- ๋ฉ”์ธํ™”๋ฉด๊ณผ ๊ฒฝ๋กœ๊ธฐ์ค€ ์ž…๋ ฅํ™”๋ฉด์—์„œ ์ •ํ•ด์ง„ ํ‚ค์›Œ๋“œ๊ฐ€ ์•„๋‹Œ ์ž…๋ ฅ์€ ๋ชจ๋‘ ์˜ˆ์™ธ์ฒ˜๋ฆฌ +- ๊ฒฝ๋กœ์กฐํšŒ์‹œ ์ถœ๋ฐœ์—ญ๊ณผ ๋„์ฐฉ์—ญ์ด ๊ฐ™์€ ๊ฒฝ์šฐ +- ์ถœ๋ฐœ์—ญ๊ณผ ๋„์ฐฉ์—ญ์ด ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ + +## ๊ฐ์ฒด +- ํ™”๋ฉด ๊ด€๋ฆฌ ๊ฐ์ฒด +- ๋ฉ”์ธ ํ™”๋ฉด +- ๊ฒฝ๋กœ ๊ธฐ์ค€ ์„ ํƒ ํ™”๋ฉด +- ๊ธฐ๋Šฅ ํ™”๋ฉด +- ์ถœ๋ ฅ +- ์ž…๋ ฅ +- ์—ญ +- ์—ญ ๋ ˆํฌ์ง€ํ† ๋ฆฌ +- ๋…ธ์„  +- ๋…ธ์„  ๋ ˆํฌ์ง€ํ† ๋ฆฌ +- ๊ตฌ๊ฐ„ +- ๊ตฌ๊ฐ„ ๋ ˆํฌ์ง€ํ† ๋ฆฌ From dfa48599edecea0dedaf9fd5b58fe6d96a7905e0 Mon Sep 17 00:00:00 2001 From: soongjamm Date: Sun, 20 Dec 2020 20:15:04 +0900 Subject: [PATCH 12/24] =?UTF-8?q?style(screen):=20ScreenModel=EC=97=90=20?= =?UTF-8?q?=EC=83=81=EC=88=98=EB=A5=BC=20=EC=B6=94=EA=B0=80=ED=95=98?= =?UTF-8?q?=EC=97=AC=20DONE:=EC=A2=85=EB=A3=8C=EB=82=98=20=EB=92=A4?= =?UTF-8?q?=EB=A1=9C=EA=B0=80=EA=B8=B0=20=EC=84=A0=ED=83=9D,=20NOTHING:?= =?UTF-8?q?=EB=8B=A4=EC=9D=8C=EC=97=90=20=ED=91=9C=EC=8B=9C=ED=95=A0=20?= =?UTF-8?q?=EC=8A=A4=ED=81=AC=EB=A6=B0=EC=9D=B4=20=EC=97=86=EC=9D=8C?= =?UTF-8?q?=EC=9D=84=20=EC=9D=98=EB=AF=B8=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/Application.java | 2 +- src/main/java/subway/{menu => Menu}/Menu.java | 9 +-------- src/main/java/subway/screen/FeatureScreen.java | 17 +++++++++++------ src/main/java/subway/screen/MainScreen.java | 4 ++-- src/main/java/subway/screen/ScreenManager.java | 11 ++++------- src/main/java/subway/screen/ScreenModel.java | 12 ++++++++++-- .../subway/screen/SelectCriteriaScreen.java | 3 +-- src/main/java/subway/view/OutputView.java | 6 +++--- 8 files changed, 33 insertions(+), 31 deletions(-) rename src/main/java/subway/{menu => Menu}/Menu.java (80%) diff --git a/src/main/java/subway/Application.java b/src/main/java/subway/Application.java index 0e5a4fcbb..426a88b67 100644 --- a/src/main/java/subway/Application.java +++ b/src/main/java/subway/Application.java @@ -15,7 +15,7 @@ public static void main(String[] args) { initialize(); ScreenManager.addNextMenuScreen(new MainScreen(scanner)); - while(!ScreenManager.isEmpty()) { + while (!ScreenManager.isEmpty()) { ScreenModel nextScreen = ScreenManager.pop(); ScreenManager.show(nextScreen); } diff --git a/src/main/java/subway/menu/Menu.java b/src/main/java/subway/Menu/Menu.java similarity index 80% rename from src/main/java/subway/menu/Menu.java rename to src/main/java/subway/Menu/Menu.java index 0e126d8ed..58dc1d440 100644 --- a/src/main/java/subway/menu/Menu.java +++ b/src/main/java/subway/Menu/Menu.java @@ -1,11 +1,4 @@ -package subway.menu; - -import org.jgrapht.alg.shortestpath.DijkstraShortestPath; -import org.jgrapht.graph.DefaultWeightedEdge; -import org.jgrapht.graph.WeightedMultigraph; -import subway.domain.SectionRepository; - -import java.util.List; +package subway.Menu; public class Menu { public enum Main { diff --git a/src/main/java/subway/screen/FeatureScreen.java b/src/main/java/subway/screen/FeatureScreen.java index 3e4857ca1..3c93bcdce 100644 --- a/src/main/java/subway/screen/FeatureScreen.java +++ b/src/main/java/subway/screen/FeatureScreen.java @@ -1,6 +1,7 @@ package subway.screen; import subway.domain.SectionRepository; +import subway.Menu.Menu; import subway.view.InputView; import java.util.Scanner; @@ -18,14 +19,18 @@ public FeatureScreen(Scanner scanner, String input) { @Override public String showScreen() { InputView inputView = new InputView(scanner); - int shortestResult = 0; - String departure = inputView.enterDeparture(); - String arrival = inputView.enterArrival(); - shortestResult = SectionRepository.findShortestPath(departure, arrival); - System.out.println(shortestResult); + if (input.equals(Menu.ROUTE_CRITERIA.SHORTEST_PATH.getCode())) { + // ์ตœ๋‹จ๊ฒฝ๋กœ by ๊ฑฐ๋ฆฌ ์ˆ˜ํ–‰ + System.out.println("[์ž„์‹œ] ์ตœ๋‹จ๊ฒฝ๋กœ by ๊ฑฐ๋ฆฌ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค."); + } - return "-1"; + if (input.equals(Menu.ROUTE_CRITERIA.SHORTEST_TIME.getCode())) { + // ์ตœ๋‹จ๊ฒฝ๋กœ by ์‹œ๊ฐ„ ์ˆ˜ํ–‰ + System.out.println("[์ž„์‹œ] ์ตœ๋‹จ๊ฒฝ๋กœ by ๊ฑฐ๋ฆฌ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค."); + } + + return DONE; } } diff --git a/src/main/java/subway/screen/MainScreen.java b/src/main/java/subway/screen/MainScreen.java index d6dabed15..feecd2d28 100644 --- a/src/main/java/subway/screen/MainScreen.java +++ b/src/main/java/subway/screen/MainScreen.java @@ -1,6 +1,6 @@ package subway.screen; -import subway.menu.Menu; +import subway.Menu.Menu; import subway.view.InputView; import subway.view.OutputView; @@ -24,7 +24,7 @@ public String showScreen() { @Override public ScreenModel getNextScreen(String input) { - if (input.equals( Menu.Main.ROUTE_INQUIRY.getCode())) { + if (input.equals(Menu.Main.ROUTE_INQUIRY.getCode())) { return new SelectCriteriaScreen(scanner); } return null; diff --git a/src/main/java/subway/screen/ScreenManager.java b/src/main/java/subway/screen/ScreenManager.java index 45733fb1a..a9011fcb4 100644 --- a/src/main/java/subway/screen/ScreenManager.java +++ b/src/main/java/subway/screen/ScreenManager.java @@ -4,12 +4,10 @@ import java.util.Stack; public class ScreenManager { - private static final String DONE = "-1"; private static Stack screens = new Stack<>(); - public static boolean isEmpty() { - if(screens.isEmpty()) { + if (screens.isEmpty()) { return true; } return false; @@ -17,7 +15,7 @@ public static boolean isEmpty() { public static void show(ScreenModel screen) { String result = screen.showScreen(); - if (result == DONE) { + if (result == ScreenModel.DONE) { return; } // todo ์œ ํšจํ•œ ์ž…๋ ฅ์ธ์ง€ ๊ฒ€์ฆํ•œ๋‹ค. @@ -27,10 +25,9 @@ public static void show(ScreenModel screen) { } public static void addNextMenuScreen(ScreenModel nextScreen) { - if (Objects.isNull(nextScreen)) { - return; + if (!Objects.isNull(nextScreen)) { + screens.push(nextScreen); } - screens.push(nextScreen); } public static ScreenModel pop() { diff --git a/src/main/java/subway/screen/ScreenModel.java b/src/main/java/subway/screen/ScreenModel.java index 5edf05eb2..c3003e7a1 100644 --- a/src/main/java/subway/screen/ScreenModel.java +++ b/src/main/java/subway/screen/ScreenModel.java @@ -1,6 +1,14 @@ package subway.screen; public interface ScreenModel { - public default String showScreen() {return "-1";} - public default ScreenModel getNextScreen(String input) {return null;} + public static final String DONE = "-1"; + public static final ScreenModel NOTHING = null; + + public default String showScreen() { + return DONE; + } + + public default ScreenModel getNextScreen(String input) { + return NOTHING; + } } diff --git a/src/main/java/subway/screen/SelectCriteriaScreen.java b/src/main/java/subway/screen/SelectCriteriaScreen.java index 80732362f..c9b196eef 100644 --- a/src/main/java/subway/screen/SelectCriteriaScreen.java +++ b/src/main/java/subway/screen/SelectCriteriaScreen.java @@ -1,6 +1,6 @@ package subway.screen; -import subway.menu.Menu; +import subway.Menu.Menu; import subway.view.InputView; import subway.view.OutputView; @@ -8,7 +8,6 @@ public class SelectCriteriaScreen implements ScreenModel { - private static final String DONE = "-1"; private final Scanner scanner; public SelectCriteriaScreen(Scanner scanner) { diff --git a/src/main/java/subway/view/OutputView.java b/src/main/java/subway/view/OutputView.java index 5ab97eb3c..9517426d6 100644 --- a/src/main/java/subway/view/OutputView.java +++ b/src/main/java/subway/view/OutputView.java @@ -1,6 +1,6 @@ package subway.view; -import subway.menu.Menu; +import subway.Menu.Menu; public class OutputView { @@ -9,7 +9,7 @@ public class OutputView { public static void printMainMenu() { String message = "## ๋ฉ”์ธ ํ™”๋ฉด" + newLine; for (Menu.Main menu : Menu.Main.values()) { - message += String.format("%s. %s" + newLine, menu.getCode(), menu.getKorean() ); + message += String.format("%s. %s" + newLine, menu.getCode(), menu.getKorean()); } System.out.println(message); } @@ -17,7 +17,7 @@ public static void printMainMenu() { public static void printCriteriaMenu() { String message = "## ๊ฒฝ๋กœ ๊ธฐ์ค€" + newLine; for (Menu.ROUTE_CRITERIA menu : Menu.ROUTE_CRITERIA.values()) { - message += String.format("%s. %s" + newLine, menu.getCode(), menu.getKorean() ); + message += String.format("%s. %s" + newLine, menu.getCode(), menu.getKorean()); } System.out.println(message); } From f4024141cad272414b119c55fb1bbfedd9d689e8 Mon Sep 17 00:00:00 2001 From: soongjamm Date: Sun, 20 Dec 2020 20:40:01 +0900 Subject: [PATCH 13/24] =?UTF-8?q?feat:=20=EA=B5=AC=EA=B0=84=EC=9D=84=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=ED=95=98=EB=8A=94=20=EB=B0=A9=EC=8B=9D?= =?UTF-8?q?=EC=9D=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/Application.java | 17 +++-- .../java/subway/domain/SectionRepository.java | 69 ++++++++----------- 2 files changed, 41 insertions(+), 45 deletions(-) diff --git a/src/main/java/subway/Application.java b/src/main/java/subway/Application.java index 426a88b67..492f72add 100644 --- a/src/main/java/subway/Application.java +++ b/src/main/java/subway/Application.java @@ -32,12 +32,17 @@ private static void initialize() { , new Line("์‹ ๋ถ„๋‹น์„ ").addTerminus("๊ฐ•๋‚จ์—ญ", "์–‘์žฌ์‹œ๋ฏผ์˜์ˆฒ์—ญ")); lines.stream().forEach(line -> LineRepository.addLine(line)); - List
sections = Arrays.asList(new Section("2ํ˜ธ์„ ", "๊ต๋Œ€์—ญ", "๊ฐ•๋‚จ์—ญ", 2, 3) - , new Section("2ํ˜ธ์„ ", "๊ฐ•๋‚จ์—ญ", "์—ญ์‚ผ์—ญ", 2, 3) - , new Section("3ํ˜ธ์„ ", "๊ต๋Œ€์—ญ", "๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ", 3, 2) - , new Section("3ํ˜ธ์„ ", "๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ", "์–‘์žฌ์—ญ", 6, 5) - , new Section("3ํ˜ธ์„ ", "์–‘์žฌ์—ญ", "๋งค๋ด‰์—ญ", 1, 1)); - sections.stream().forEach(section -> SectionRepository.addSection(section)); + SectionRepository.addSection("2ํ˜ธ์„ ", "๊ฐ•๋‚จ์—ญ", 1); + SectionRepository.addSection("3ํ˜ธ์„ ", "๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ", 1); + SectionRepository.addSection("3ํ˜ธ์„ ", "์–‘์žฌ์—ญ", 2); + SectionRepository.addSection("์‹ ๋ถ„๋‹น์„ ", "์–‘์žฌ์—ญ", 1); + +// List
sections = Arrays.asList(new Section("2ํ˜ธ์„ ", "๊ฐ•๋‚จ์—ญ", 1), +// new Section("3ํ˜ธ์„ ", "๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ", 1), +// new Section("3ํ˜ธ์„ ", "์–‘์žฌ์—ญ", 2), +// new Section("์‹ ๋ถ„๋‹น์„ ", "์–‘์žฌ์—ญ", 1) +// +// sections.stream().forEach(section -> SectionRepository.addSection(section)); } } diff --git a/src/main/java/subway/domain/SectionRepository.java b/src/main/java/subway/domain/SectionRepository.java index 1d92ee180..362d6c208 100644 --- a/src/main/java/subway/domain/SectionRepository.java +++ b/src/main/java/subway/domain/SectionRepository.java @@ -1,52 +1,43 @@ package subway.domain; -import org.jgrapht.alg.shortestpath.DijkstraShortestPath; import org.jgrapht.graph.DefaultWeightedEdge; import org.jgrapht.graph.WeightedMultigraph; -import java.util.ArrayList; -import java.util.List; - public class SectionRepository { static WeightedMultigraph graph = new WeightedMultigraph(DefaultWeightedEdge.class); - static List
sections = new ArrayList<>(); - - public static List
sections() { - return sections; - } - public static void addSection(Section section) { - sections.add(section); - addVertex(section.getDeparture(), section.getArrival()); - addWeight(section.getDeparture(), section.getArrival(), section.getCostTime()); + public static void addSection(String lineName, String stationName, int sequence) { + Line line = LineRepository.findLine(lineName); + Station station = StationRepository.findStation(stationName); + line.addSection(sequence, station); } - private static void addWeight(Station departure, Station arrival, int costTime) { - if (!graph.containsEdge(graph.addEdge(departure.getName(), arrival.getName()))) { - graph.setEdgeWeight(graph.addEdge(departure.getName(), arrival.getName()), costTime); - } - } - - private static void addVertex(Station departure, Station arrival) { - if (!graph.containsVertex(departure.getName())) { - graph.addVertex(departure.getName()); - } - if (!graph.containsVertex(arrival.getName())) { - graph.addVertex(arrival.getName()); - } - } - - public static int findShortestPath(String departure, String destination) { - - DijkstraShortestPath dijkstraShortestPath = new DijkstraShortestPath(graph); - List shortestPath = dijkstraShortestPath.getPath(departure, destination).getVertexList(); - - return (int) sections.stream() - .filter(section -> section.hasStation(departure, destination)) - .mapToInt(Section::getDistance) - .sum(); - - } +// private static void addWeight(Station departure, Station arrival, int costTime) { +// if (!graph.containsEdge(graph.addEdge(departure.getName(), arrival.getName()))) { +// graph.setEdgeWeight(graph.addEdge(departure.getName(), arrival.getName()), costTime); +// } +// } +// +// private static void addVertex(Station departure, Station arrival) { +// if (!graph.containsVertex(departure.getName())) { +// graph.addVertex(departure.getName()); +// } +// if (!graph.containsVertex(arrival.getName())) { +// graph.addVertex(arrival.getName()); +// } +// } +// +// public static int findShortestPath(String departure, String destination) { +// +// DijkstraShortestPath dijkstraShortestPath = new DijkstraShortestPath(graph); +// List shortestPath = dijkstraShortestPath.getPath(departure, destination).getVertexList(); +// +// return (int) sections.stream() +// .filter(section -> section.hasStation(departure, destination)) +// .mapToInt(Section::getDistance) +// .sum(); +// +// } } From c18965ee8b2cf88a2c57757e83ce9264d076f91e Mon Sep 17 00:00:00 2001 From: soongjamm Date: Sun, 20 Dec 2020 21:15:33 +0900 Subject: [PATCH 14/24] =?UTF-8?q?feat:=20=EA=B5=AC=EA=B0=84=EC=9D=98=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4(=EA=B1=B0=EB=A6=AC,=20=EC=8B=9C=EA=B0=84)=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=ED=95=98=EB=8A=94=20=EB=B0=A9=EC=8B=9D?= =?UTF-8?q?=EC=9D=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/Application.java | 8 ++++ src/main/java/subway/domain/Section.java | 40 ++++--------------- .../java/subway/domain/SectionRepository.java | 26 ++++++++---- 3 files changed, 33 insertions(+), 41 deletions(-) diff --git a/src/main/java/subway/Application.java b/src/main/java/subway/Application.java index 492f72add..2c27cca74 100644 --- a/src/main/java/subway/Application.java +++ b/src/main/java/subway/Application.java @@ -37,6 +37,14 @@ private static void initialize() { SectionRepository.addSection("3ํ˜ธ์„ ", "์–‘์žฌ์—ญ", 2); SectionRepository.addSection("์‹ ๋ถ„๋‹น์„ ", "์–‘์žฌ์—ญ", 1); + SectionRepository.addSectinonDistanceAndCost("๊ต๋Œ€์—ญ", "๊ฐ•๋‚จ์—ญ", 2, 3); + SectionRepository.addSectinonDistanceAndCost("๊ฐ•๋‚จ์—ญ", "์—ญ์‚ผ์—ญ", 2, 3); + SectionRepository.addSectinonDistanceAndCost("๊ต๋Œ€์—ญ", "๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ", 3, 2); + SectionRepository.addSectinonDistanceAndCost("๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ", "์–‘์žฌ์—ญ", 6, 5); + SectionRepository.addSectinonDistanceAndCost("์–‘์žฌ์—ญ", "๋งค๋ด‰์—ญ", 1, 1); + SectionRepository.addSectinonDistanceAndCost("๊ฐ•๋‚จ์—ญ", "์–‘์žฌ์—ญ", 2, 8); + SectionRepository.addSectinonDistanceAndCost("์–‘์žฌ์—ญ", "์–‘์žฌ์‹œ๋ฏผ์˜์ˆฒ์—ญ", 10, 3); + // List
sections = Arrays.asList(new Section("2ํ˜ธ์„ ", "๊ฐ•๋‚จ์—ญ", 1), // new Section("3ํ˜ธ์„ ", "๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ", 1), // new Section("3ํ˜ธ์„ ", "์–‘์žฌ์—ญ", 2), diff --git a/src/main/java/subway/domain/Section.java b/src/main/java/subway/domain/Section.java index b45bfb86a..ba2c83dbe 100644 --- a/src/main/java/subway/domain/Section.java +++ b/src/main/java/subway/domain/Section.java @@ -1,47 +1,21 @@ package subway.domain; -public class Section { +import java.util.HashSet; +import java.util.Set; - private Line line; +public class Section { - private Station departure; - private Station arrival; + private Set stations = new HashSet<>(); private int distance; private int costTime; - public Section(String lineName, String departureName, String arrivalName, int distance, int costTime) { - Line line = LineRepository.findLine(lineName); - Station departure = StationRepository.findStation(departureName); - Station arrival = StationRepository.findStation(arrivalName); - - this.line = line; - this.departure = departure; - this.arrival = arrival; + public Section(String station1, String station2, int distance, int costTime) { + stations.add(station1); + stations.add(station2); this.distance = distance; this.costTime = costTime; - } - - public boolean hasStation(String station1, String station2) { - if ((station1.equals(arrival.getName()) || station2.equals(arrival.getName())) - && (station1.equals(departure.getName()) || station2.equals(departure.getName()))) { - return true; - } - return false; - } - public int getDistance() { - return distance; } - public Station getDeparture() { - return departure; - } - public Station getArrival() { - return arrival; - } - - public int getCostTime() { - return costTime; - } } diff --git a/src/main/java/subway/domain/SectionRepository.java b/src/main/java/subway/domain/SectionRepository.java index 362d6c208..bc0ea6213 100644 --- a/src/main/java/subway/domain/SectionRepository.java +++ b/src/main/java/subway/domain/SectionRepository.java @@ -3,9 +3,13 @@ import org.jgrapht.graph.DefaultWeightedEdge; import org.jgrapht.graph.WeightedMultigraph; +import java.util.ArrayList; +import java.util.List; + public class SectionRepository { static WeightedMultigraph graph = new WeightedMultigraph(DefaultWeightedEdge.class); + static List
sections = new ArrayList<>(); public static void addSection(String lineName, String stationName, int sequence) { Line line = LineRepository.findLine(lineName); @@ -13,20 +17,26 @@ public static void addSection(String lineName, String stationName, int sequence) line.addSection(sequence, station); } + public static void addSectinonDistanceAndCost(String station1, String station2, int distance, int cost) { + addVertex(station1, station2); + sections.add(new Section(station1, station2, distance, cost)); + } + + private static void addVertex(String station1, String station2) { + if (!graph.containsVertex(station1)) { + graph.addVertex(station1); + } + if (!graph.containsVertex(station2)) { + graph.addVertex(station2); + } + } + // private static void addWeight(Station departure, Station arrival, int costTime) { // if (!graph.containsEdge(graph.addEdge(departure.getName(), arrival.getName()))) { // graph.setEdgeWeight(graph.addEdge(departure.getName(), arrival.getName()), costTime); // } // } // -// private static void addVertex(Station departure, Station arrival) { -// if (!graph.containsVertex(departure.getName())) { -// graph.addVertex(departure.getName()); -// } -// if (!graph.containsVertex(arrival.getName())) { -// graph.addVertex(arrival.getName()); -// } -// } // // public static int findShortestPath(String departure, String destination) { // From 43d538f9fa8fcf0c6b83dc50940471315cf2a0f0 Mon Sep 17 00:00:00 2001 From: soongjamm Date: Sun, 20 Dec 2020 23:02:36 +0900 Subject: [PATCH 15/24] =?UTF-8?q?feat:=20=EA=B1=B0=EB=A6=AC=EA=B8=B0?= =?UTF-8?q?=EC=A4=80=20=EC=B5=9C=EC=86=8C=EA=B2=BD=EB=A1=9C=EB=A5=BC=20?= =?UTF-8?q?=EA=B5=AC=ED=95=A0=20=EB=95=8C,=20=EA=B1=B0=EB=A6=AC=20?= =?UTF-8?q?=EA=B3=84=EC=82=B0=EA=B9=8C=EC=A7=80=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/Application.java | 1 - src/main/java/subway/domain/Section.java | 9 ++++ .../java/subway/domain/SectionRepository.java | 46 +++++++++++++++++-- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/main/java/subway/Application.java b/src/main/java/subway/Application.java index 2c27cca74..ca2cb919a 100644 --- a/src/main/java/subway/Application.java +++ b/src/main/java/subway/Application.java @@ -44,7 +44,6 @@ private static void initialize() { SectionRepository.addSectinonDistanceAndCost("์–‘์žฌ์—ญ", "๋งค๋ด‰์—ญ", 1, 1); SectionRepository.addSectinonDistanceAndCost("๊ฐ•๋‚จ์—ญ", "์–‘์žฌ์—ญ", 2, 8); SectionRepository.addSectinonDistanceAndCost("์–‘์žฌ์—ญ", "์–‘์žฌ์‹œ๋ฏผ์˜์ˆฒ์—ญ", 10, 3); - // List
sections = Arrays.asList(new Section("2ํ˜ธ์„ ", "๊ฐ•๋‚จ์—ญ", 1), // new Section("3ํ˜ธ์„ ", "๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ", 1), // new Section("3ํ˜ธ์„ ", "์–‘์žฌ์—ญ", 2), diff --git a/src/main/java/subway/domain/Section.java b/src/main/java/subway/domain/Section.java index ba2c83dbe..2c85f4ebf 100644 --- a/src/main/java/subway/domain/Section.java +++ b/src/main/java/subway/domain/Section.java @@ -14,8 +14,17 @@ public Section(String station1, String station2, int distance, int costTime) { stations.add(station2); this.distance = distance; this.costTime = costTime; + } + public Set getStations() { + return stations; } + public int getDistance() { + return distance; + } + public int getCostTime() { + return costTime; + } } diff --git a/src/main/java/subway/domain/SectionRepository.java b/src/main/java/subway/domain/SectionRepository.java index bc0ea6213..f9c9a9cbc 100644 --- a/src/main/java/subway/domain/SectionRepository.java +++ b/src/main/java/subway/domain/SectionRepository.java @@ -1,5 +1,7 @@ package subway.domain; +import org.jgrapht.GraphPath; +import org.jgrapht.alg.shortestpath.DijkstraShortestPath; import org.jgrapht.graph.DefaultWeightedEdge; import org.jgrapht.graph.WeightedMultigraph; @@ -8,7 +10,8 @@ public class SectionRepository { - static WeightedMultigraph graph = new WeightedMultigraph(DefaultWeightedEdge.class); + static WeightedMultigraph graphByDistance = new WeightedMultigraph(DefaultWeightedEdge.class); + static WeightedMultigraph graphByCost = new WeightedMultigraph(DefaultWeightedEdge.class); static List
sections = new ArrayList<>(); public static void addSection(String lineName, String stationName, int sequence) { @@ -19,15 +22,48 @@ public static void addSection(String lineName, String stationName, int sequence) public static void addSectinonDistanceAndCost(String station1, String station2, int distance, int cost) { addVertex(station1, station2); + setEdgeWeight(station1, station2, distance, cost); sections.add(new Section(station1, station2, distance, cost)); } + private static void setEdgeWeight(String station1, String station2, int distance, int cost) { + graphByDistance.setEdgeWeight(graphByDistance.addEdge(station1, station2), distance); + graphByCost.setEdgeWeight(graphByCost.addEdge(station1, station2), cost); + } + + public static void findShortestPathByDistance(String departure, String destination) { + DijkstraShortestPath dijkstraShortestPath = new DijkstraShortestPath(graphByDistance); + GraphPath graphPath = dijkstraShortestPath.getPath(departure, destination); + + List path = graphPath.getVertexList(); + double shortestPathDistance = graphPath.getWeight(); + int costTime = calculateCostTime(path); + } + + private static int calculateCostTime(List path) { + for(int i=0; i Date: Sun, 20 Dec 2020 23:09:55 +0900 Subject: [PATCH 16/24] =?UTF-8?q?feat:=20=EA=B1=B0=EB=A6=AC=EA=B8=B0?= =?UTF-8?q?=EC=A4=80=20=EC=B5=9C=EC=86=8C=EA=B2=BD=EB=A1=9C=EB=A5=BC=20?= =?UTF-8?q?=EA=B5=AC=ED=95=A0=20=EB=95=8C,=20=EC=86=8C=EC=9A=94=EB=90=98?= =?UTF-8?q?=EB=8A=94=20=EC=8B=9C=EA=B0=84=20=EA=B3=84=EC=82=B0=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/domain/SectionRepository.java | 14 +++++++++++--- src/main/java/subway/screen/FeatureScreen.java | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/subway/domain/SectionRepository.java b/src/main/java/subway/domain/SectionRepository.java index f9c9a9cbc..6ef92b776 100644 --- a/src/main/java/subway/domain/SectionRepository.java +++ b/src/main/java/subway/domain/SectionRepository.java @@ -6,7 +6,9 @@ import org.jgrapht.graph.WeightedMultigraph; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; public class SectionRepository { @@ -37,15 +39,21 @@ public static void findShortestPathByDistance(String departure, String destinati List path = graphPath.getVertexList(); double shortestPathDistance = graphPath.getWeight(); - int costTime = calculateCostTime(path); + int costTime = (int) sections.stream().filter(section -> calculateCostTime(path, section)).mapToInt(Section::getCostTime).sum(); + + System.out.println(shortestPathDistance + " " + costTime); } - private static int calculateCostTime(List path) { + private static boolean calculateCostTime(List path, Section section) { + Set stations = section.getStations(); for(int i=0; i Date: Mon, 21 Dec 2020 01:34:07 +0900 Subject: [PATCH 17/24] =?UTF-8?q?refactor:=20=EC=B5=9C=EB=8B=A8=EA=B2=BD?= =?UTF-8?q?=EB=A1=9C=EC=97=90=20=ED=8F=AC=ED=95=A8=EB=90=98=EB=8A=94=20?= =?UTF-8?q?=EA=B5=AC=EA=B0=84=EC=9D=B8=EC=A7=80=20=ED=99=95=EC=9D=B8?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=A9=94=EC=86=8C=EB=93=9C=EB=A5=BC=20Sec?= =?UTF-8?q?tion=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/domain/Section.java | 10 +++++ .../java/subway/domain/SectionRepository.java | 41 +++---------------- 2 files changed, 16 insertions(+), 35 deletions(-) diff --git a/src/main/java/subway/domain/Section.java b/src/main/java/subway/domain/Section.java index 2c85f4ebf..e1270705c 100644 --- a/src/main/java/subway/domain/Section.java +++ b/src/main/java/subway/domain/Section.java @@ -1,6 +1,7 @@ package subway.domain; import java.util.HashSet; +import java.util.List; import java.util.Set; public class Section { @@ -16,6 +17,15 @@ public Section(String station1, String station2, int distance, int costTime) { this.costTime = costTime; } + public boolean isInShortestPath(List shortestPath) { + for(int i=0; i getStations() { return stations; } diff --git a/src/main/java/subway/domain/SectionRepository.java b/src/main/java/subway/domain/SectionRepository.java index 6ef92b776..08ea87c7c 100644 --- a/src/main/java/subway/domain/SectionRepository.java +++ b/src/main/java/subway/domain/SectionRepository.java @@ -6,9 +6,7 @@ import org.jgrapht.graph.WeightedMultigraph; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; public class SectionRepository { @@ -37,23 +35,15 @@ public static void findShortestPathByDistance(String departure, String destinati DijkstraShortestPath dijkstraShortestPath = new DijkstraShortestPath(graphByDistance); GraphPath graphPath = dijkstraShortestPath.getPath(departure, destination); - List path = graphPath.getVertexList(); double shortestPathDistance = graphPath.getWeight(); - int costTime = (int) sections.stream().filter(section -> calculateCostTime(path, section)).mapToInt(Section::getCostTime).sum(); - - System.out.println(shortestPathDistance + " " + costTime); + int costTime = calculateCostTime(graphPath.getVertexList()); } - private static boolean calculateCostTime(List path, Section section) { - Set stations = section.getStations(); - for(int i=0; i shortestPath) { + return sections.stream() + .filter(section -> section.isInShortestPath(shortestPath)) + .mapToInt(Section::getCostTime) + .sum(); } public static void findShortestPathByCost(String departure, String destination) { @@ -75,23 +65,4 @@ private static void addVertex(String station1, String station2) { } } -// private static void addWeight(Station departure, Station arrival, int costTime) { -// if (!graph.containsEdge(graph.addEdge(departure.getName(), arrival.getName()))) { -// graph.setEdgeWeight(graph.addEdge(departure.getName(), arrival.getName()), costTime); -// } -// } -// -// -// public static int findShortestPath(String departure, String destination) { -// -// DijkstraShortestPath dijkstraShortestPath = new DijkstraShortestPath(graph); -// List shortestPath = dijkstraShortestPath.getPath(departure, destination).getVertexList(); -// -// return (int) sections.stream() -// .filter(section -> section.hasStation(departure, destination)) -// .mapToInt(Section::getDistance) -// .sum(); -// -// } - } From 0af7958019347d55878a1875255a0f3ce1ddca44 Mon Sep 17 00:00:00 2001 From: soongjamm Date: Mon, 21 Dec 2020 01:45:02 +0900 Subject: [PATCH 18/24] =?UTF-8?q?feat:=20=EA=B2=BD=EB=A1=9C=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EA=B2=B0=EA=B3=BC=20=EC=B6=9C=EB=A0=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/Application.java | 6 ------ src/main/java/subway/domain/SectionRepository.java | 7 +++++-- src/main/java/subway/view/OutputView.java | 11 +++++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/subway/Application.java b/src/main/java/subway/Application.java index ca2cb919a..691658d5b 100644 --- a/src/main/java/subway/Application.java +++ b/src/main/java/subway/Application.java @@ -44,12 +44,6 @@ private static void initialize() { SectionRepository.addSectinonDistanceAndCost("์–‘์žฌ์—ญ", "๋งค๋ด‰์—ญ", 1, 1); SectionRepository.addSectinonDistanceAndCost("๊ฐ•๋‚จ์—ญ", "์–‘์žฌ์—ญ", 2, 8); SectionRepository.addSectinonDistanceAndCost("์–‘์žฌ์—ญ", "์–‘์žฌ์‹œ๋ฏผ์˜์ˆฒ์—ญ", 10, 3); -// List
sections = Arrays.asList(new Section("2ํ˜ธ์„ ", "๊ฐ•๋‚จ์—ญ", 1), -// new Section("3ํ˜ธ์„ ", "๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ", 1), -// new Section("3ํ˜ธ์„ ", "์–‘์žฌ์—ญ", 2), -// new Section("์‹ ๋ถ„๋‹น์„ ", "์–‘์žฌ์—ญ", 1) -// -// sections.stream().forEach(section -> SectionRepository.addSection(section)); } } diff --git a/src/main/java/subway/domain/SectionRepository.java b/src/main/java/subway/domain/SectionRepository.java index 08ea87c7c..d0236a021 100644 --- a/src/main/java/subway/domain/SectionRepository.java +++ b/src/main/java/subway/domain/SectionRepository.java @@ -4,6 +4,7 @@ import org.jgrapht.alg.shortestpath.DijkstraShortestPath; import org.jgrapht.graph.DefaultWeightedEdge; import org.jgrapht.graph.WeightedMultigraph; +import subway.view.OutputView; import java.util.ArrayList; import java.util.List; @@ -35,8 +36,10 @@ public static void findShortestPathByDistance(String departure, String destinati DijkstraShortestPath dijkstraShortestPath = new DijkstraShortestPath(graphByDistance); GraphPath graphPath = dijkstraShortestPath.getPath(departure, destination); - double shortestPathDistance = graphPath.getWeight(); - int costTime = calculateCostTime(graphPath.getVertexList()); + List shortestPath = graphPath.getVertexList(); + int shortestPathDistance = (int)graphPath.getWeight(); + int costTime = calculateCostTime(shortestPath); + OutputView.printRouteResult(shortestPath, shortestPathDistance, costTime); } private static int calculateCostTime(List shortestPath) { diff --git a/src/main/java/subway/view/OutputView.java b/src/main/java/subway/view/OutputView.java index 9517426d6..7ec1e9476 100644 --- a/src/main/java/subway/view/OutputView.java +++ b/src/main/java/subway/view/OutputView.java @@ -2,6 +2,8 @@ import subway.Menu.Menu; +import java.util.List; + public class OutputView { private static final String newLine = "\n"; @@ -26,4 +28,13 @@ public static void printRouteResult() { } + public static void printRouteResult(List shortestPath, int shortestPathDistance, int costTime) { + System.out.println("## ์กฐํšŒ ๊ฒฐ๊ณผ"); + System.out.println("[INFO] ---"); + System.out.println(String.format("์ด ๊ฑฐ๋ฆฌ: %dkm", shortestPathDistance)); + System.out.println(String.format("์ด ์†Œ์š”์‹œ๊ฐ„: %d๋ถ„", costTime)); + System.out.println("[INFO] ---"); + shortestPath.stream() + .forEach(station -> System.out.println("[INFO] " + station)); + } } From 832ea11a281a1b48c46a53df8ca92990e8e28521 Mon Sep 17 00:00:00 2001 From: soongjamm Date: Mon, 21 Dec 2020 01:52:33 +0900 Subject: [PATCH 19/24] =?UTF-8?q?fix:=20=EC=A1=B0=ED=9A=8C=ED=9B=84=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=A8=20=EC=A2=85=EB=A3=8C?= =?UTF-8?q?=EB=90=98=EB=8A=94=20=ED=98=84=EC=83=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradlew | 8 ++++---- src/main/java/subway/screen/FeatureScreen.java | 6 +++++- src/main/java/subway/screen/ScreenManager.java | 2 +- src/main/java/subway/screen/ScreenModel.java | 5 +++-- src/main/java/subway/screen/SelectCriteriaScreen.java | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/gradlew b/gradlew index 2fe81a7d9..9b9244cd2 100755 --- a/gradlew +++ b/gradlew @@ -34,7 +34,7 @@ while [ -h "$PRG" ] ; do else PRG=`dirname "$PRG"`"/$link" fi -done +GO_BACK SAVED="`pwd`" cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME="`pwd -P`" @@ -137,7 +137,7 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then for dir in $ROOTDIRSRAW ; do ROOTDIRS="$ROOTDIRS$SEP$dir" SEP="|" - done + GO_BACK OURCYGPATTERN="(^($ROOTDIRS))" # Add a user-defined pattern to the cygpath arguments if [ "$GRADLE_CYGPATTERN" != "" ] ; then @@ -155,7 +155,7 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then eval `echo args$i`="\"$arg\"" fi i=`expr $i + 1` - done + GO_BACK case $i in 0) set -- ;; 1) set -- "$args0" ;; @@ -172,7 +172,7 @@ fi # Escape application args save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; GO_BACK echo " " } APP_ARGS=`save "$@"` diff --git a/src/main/java/subway/screen/FeatureScreen.java b/src/main/java/subway/screen/FeatureScreen.java index 661d739cf..c40c47176 100644 --- a/src/main/java/subway/screen/FeatureScreen.java +++ b/src/main/java/subway/screen/FeatureScreen.java @@ -31,7 +31,11 @@ public String showScreen() { System.out.println("[์ž„์‹œ] ์ตœ๋‹จ๊ฒฝ๋กœ by ๊ฑฐ๋ฆฌ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค."); } - return DONE; + return GO_MAIN; } + @Override + public ScreenModel getNextScreen(String input) { + return new MainScreen(scanner); + } } diff --git a/src/main/java/subway/screen/ScreenManager.java b/src/main/java/subway/screen/ScreenManager.java index a9011fcb4..13d537aab 100644 --- a/src/main/java/subway/screen/ScreenManager.java +++ b/src/main/java/subway/screen/ScreenManager.java @@ -15,7 +15,7 @@ public static boolean isEmpty() { public static void show(ScreenModel screen) { String result = screen.showScreen(); - if (result == ScreenModel.DONE) { + if (result == ScreenModel.GO_BACK) { return; } // todo ์œ ํšจํ•œ ์ž…๋ ฅ์ธ์ง€ ๊ฒ€์ฆํ•œ๋‹ค. diff --git a/src/main/java/subway/screen/ScreenModel.java b/src/main/java/subway/screen/ScreenModel.java index c3003e7a1..f77010e19 100644 --- a/src/main/java/subway/screen/ScreenModel.java +++ b/src/main/java/subway/screen/ScreenModel.java @@ -1,11 +1,12 @@ package subway.screen; public interface ScreenModel { - public static final String DONE = "-1"; + public static final String GO_MAIN = "0"; + public static final String GO_BACK = "-1"; public static final ScreenModel NOTHING = null; public default String showScreen() { - return DONE; + return GO_BACK; } public default ScreenModel getNextScreen(String input) { diff --git a/src/main/java/subway/screen/SelectCriteriaScreen.java b/src/main/java/subway/screen/SelectCriteriaScreen.java index c9b196eef..bc49b3700 100644 --- a/src/main/java/subway/screen/SelectCriteriaScreen.java +++ b/src/main/java/subway/screen/SelectCriteriaScreen.java @@ -21,7 +21,7 @@ public String showScreen() { OutputView.printCriteriaMenu(); String input = inputView.enterFeature(); if (input.equals(Menu.Main.QUIT)) { - return DONE; + return GO_BACK; } return input; } From 8a6d5dffd1b5d232feab73985adc0307c8706eee Mon Sep 17 00:00:00 2001 From: soongjamm Date: Mon, 21 Dec 2020 09:32:13 +0900 Subject: [PATCH 20/24] =?UTF-8?q?feat:=20=EA=B0=81=20=EB=A9=94=EB=89=B4=20?= =?UTF-8?q?=EC=84=A0=ED=83=9D=ED=99=94=EB=A9=B4=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=9E=98=EB=AA=BB=20=EC=9E=85=EB=A0=A5=EB=90=9C=20=EA=B0=92=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/Application.java | 9 +++++++-- src/main/java/subway/screen/MainScreen.java | 12 ++++++++++-- src/main/java/subway/screen/ScreenManager.java | 2 -- src/main/java/subway/screen/ScreenModel.java | 8 ++++++++ .../java/subway/screen/SelectCriteriaScreen.java | 12 +++++++++++- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/main/java/subway/Application.java b/src/main/java/subway/Application.java index 691658d5b..5dba4eed8 100644 --- a/src/main/java/subway/Application.java +++ b/src/main/java/subway/Application.java @@ -16,8 +16,13 @@ public static void main(String[] args) { ScreenManager.addNextMenuScreen(new MainScreen(scanner)); while (!ScreenManager.isEmpty()) { - ScreenModel nextScreen = ScreenManager.pop(); - ScreenManager.show(nextScreen); + try { + ScreenModel nextScreen = ScreenManager.pop(); + ScreenManager.show(nextScreen); + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + ScreenManager.addNextMenuScreen(new MainScreen(scanner)); + } } } diff --git a/src/main/java/subway/screen/MainScreen.java b/src/main/java/subway/screen/MainScreen.java index feecd2d28..fb7e25466 100644 --- a/src/main/java/subway/screen/MainScreen.java +++ b/src/main/java/subway/screen/MainScreen.java @@ -4,6 +4,7 @@ import subway.view.InputView; import subway.view.OutputView; +import java.util.Arrays; import java.util.Scanner; public class MainScreen implements ScreenModel { @@ -24,9 +25,16 @@ public String showScreen() { @Override public ScreenModel getNextScreen(String input) { - if (input.equals(Menu.Main.ROUTE_INQUIRY.getCode())) { + if (anyMatchToMenu(input)){ return new SelectCriteriaScreen(scanner); } - return null; + throw new IllegalArgumentException("[ERROR] ์ž˜๋ชป๋œ ์ž…๋ ฅ์ž…๋‹ˆ๋‹ค.\n"); } + + @Override + public boolean anyMatchToMenu(String input) { + return Arrays.stream(Menu.Main.values()) + .anyMatch(menu -> menu.getCode().equals(input)); + } + } diff --git a/src/main/java/subway/screen/ScreenManager.java b/src/main/java/subway/screen/ScreenManager.java index 13d537aab..b7ce74e1a 100644 --- a/src/main/java/subway/screen/ScreenManager.java +++ b/src/main/java/subway/screen/ScreenManager.java @@ -18,8 +18,6 @@ public static void show(ScreenModel screen) { if (result == ScreenModel.GO_BACK) { return; } - // todo ์œ ํšจํ•œ ์ž…๋ ฅ์ธ์ง€ ๊ฒ€์ฆํ•œ๋‹ค. - addNextMenuScreen(screen.getNextScreen(result)); } diff --git a/src/main/java/subway/screen/ScreenModel.java b/src/main/java/subway/screen/ScreenModel.java index f77010e19..45a0d35d0 100644 --- a/src/main/java/subway/screen/ScreenModel.java +++ b/src/main/java/subway/screen/ScreenModel.java @@ -1,5 +1,9 @@ package subway.screen; +import subway.Menu.Menu; + +import java.util.Arrays; + public interface ScreenModel { public static final String GO_MAIN = "0"; public static final String GO_BACK = "-1"; @@ -12,4 +16,8 @@ public default String showScreen() { public default ScreenModel getNextScreen(String input) { return NOTHING; } + + public default boolean anyMatchToMenu(String input) { + return false; + } } diff --git a/src/main/java/subway/screen/SelectCriteriaScreen.java b/src/main/java/subway/screen/SelectCriteriaScreen.java index bc49b3700..11fe93e36 100644 --- a/src/main/java/subway/screen/SelectCriteriaScreen.java +++ b/src/main/java/subway/screen/SelectCriteriaScreen.java @@ -4,6 +4,7 @@ import subway.view.InputView; import subway.view.OutputView; +import java.util.Arrays; import java.util.Scanner; public class SelectCriteriaScreen implements ScreenModel { @@ -28,7 +29,16 @@ public String showScreen() { @Override public ScreenModel getNextScreen(String input) { - return new FeatureScreen(scanner, input); + if (anyMatchToMenu(input)) { + return new FeatureScreen(scanner, input); + } + throw new IllegalArgumentException("[ERROR] ์ž˜๋ชป๋œ ์ž…๋ ฅ์ž…๋‹ˆ๋‹ค.\n"); + } + + @Override + public boolean anyMatchToMenu(String input) { + return Arrays.stream(Menu.ROUTE_CRITERIA.values()) + .anyMatch(menu -> menu.getCode().equals(input)); } } From b58bc2da5ab3509f4861d4fd434001ebe72d1a53 Mon Sep 17 00:00:00 2001 From: soongjamm Date: Mon, 21 Dec 2020 09:52:02 +0900 Subject: [PATCH 21/24] =?UTF-8?q?feat:=20=EA=B2=BD=EB=A1=9C=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=8B=9C=20=EC=97=AD=EC=9D=84=20=EA=B2=80=EC=A6=9D?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/subway/domain/SectionRepository.java | 15 ++++++++++++--- src/main/java/subway/screen/FeatureScreen.java | 9 ++++----- src/main/java/subway/view/InputView.java | 14 +------------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/main/java/subway/domain/SectionRepository.java b/src/main/java/subway/domain/SectionRepository.java index d0236a021..ccb61936a 100644 --- a/src/main/java/subway/domain/SectionRepository.java +++ b/src/main/java/subway/domain/SectionRepository.java @@ -33,15 +33,25 @@ private static void setEdgeWeight(String station1, String station2, int distance } public static void findShortestPathByDistance(String departure, String destination) { + validateDepartureAndDestination(departure, destination); + DijkstraShortestPath dijkstraShortestPath = new DijkstraShortestPath(graphByDistance); GraphPath graphPath = dijkstraShortestPath.getPath(departure, destination); - List shortestPath = graphPath.getVertexList(); int shortestPathDistance = (int)graphPath.getWeight(); int costTime = calculateCostTime(shortestPath); OutputView.printRouteResult(shortestPath, shortestPathDistance, costTime); } + private static void validateDepartureAndDestination(String departure, String destination) { + StationRepository.findStation(departure); + StationRepository.deleteStation(destination); + if (departure.equals(destination)) { + throw new IllegalArgumentException("[ERROR] ์ถœ๋ฐœ์—ญ๊ณผ ๋„์ฐฉ์—ญ์ด ๊ฐ™์Šต๋‹ˆ๋‹ค."); + } + } + + private static int calculateCostTime(List shortestPath) { return sections.stream() .filter(section -> section.isInShortestPath(shortestPath)) @@ -49,7 +59,7 @@ private static int calculateCostTime(List shortestPath) { .sum(); } - public static void findShortestPathByCost(String departure, String destination) { + public static void findShortestPathByCostTime(String departure, String destination) { } @@ -67,5 +77,4 @@ private static void addVertex(String station1, String station2) { graphByCost.addVertex(station2); } } - } diff --git a/src/main/java/subway/screen/FeatureScreen.java b/src/main/java/subway/screen/FeatureScreen.java index c40c47176..4e8cd4ffb 100644 --- a/src/main/java/subway/screen/FeatureScreen.java +++ b/src/main/java/subway/screen/FeatureScreen.java @@ -19,16 +19,15 @@ public FeatureScreen(Scanner scanner, String input) { @Override public String showScreen() { InputView inputView = new InputView(scanner); + String departure = inputView.enterDeparture(); + String destination = inputView.enterDestination(); if (input.equals(Menu.ROUTE_CRITERIA.SHORTEST_PATH.getCode())) { - // ์ตœ๋‹จ๊ฒฝ๋กœ by ๊ฑฐ๋ฆฌ ์ˆ˜ํ–‰ - System.out.println("[์ž„์‹œ] ์ตœ๋‹จ๊ฒฝ๋กœ by ๊ฑฐ๋ฆฌ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค."); - SectionRepository.findShortestPathByDistance("๊ต๋Œ€์—ญ", "์–‘์žฌ์—ญ"); + SectionRepository.findShortestPathByDistance(departure, destination); } if (input.equals(Menu.ROUTE_CRITERIA.SHORTEST_TIME.getCode())) { - // ์ตœ๋‹จ๊ฒฝ๋กœ by ์‹œ๊ฐ„ ์ˆ˜ํ–‰ - System.out.println("[์ž„์‹œ] ์ตœ๋‹จ๊ฒฝ๋กœ by ๊ฑฐ๋ฆฌ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค."); + SectionRepository.findShortestPathByCostTime(departure, destination); } return GO_MAIN; diff --git a/src/main/java/subway/view/InputView.java b/src/main/java/subway/view/InputView.java index 5a0f624dd..6a49f3f60 100644 --- a/src/main/java/subway/view/InputView.java +++ b/src/main/java/subway/view/InputView.java @@ -15,24 +15,12 @@ public String enterFeature() { return scanner.nextLine(); } - public void enterCriteria() { - - } - - public void enterDepartualStation() { - - } - - public void enterArrivalStation() { - - } - public String enterDeparture() { System.out.println("## ์ถœ๋ฐœ์—ญ์„ ์ž…๋ ฅํ•˜์„ธ์š”."); return scanner.nextLine(); } - public String enterArrival() { + public String enterDestination() { System.out.println("## ๋„์ฐฉ์—ญ์„ ์ž…๋ ฅํ•˜์„ธ์š”."); return scanner.nextLine(); } From 10bef674a5992148ea7b71a7a0de47c92404b20c Mon Sep 17 00:00:00 2001 From: soongjamm Date: Mon, 21 Dec 2020 10:01:09 +0900 Subject: [PATCH 22/24] =?UTF-8?q?style:=20=EC=8B=9C=EA=B0=84=EA=B3=BC=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=EB=90=9C=20=EC=9D=B4=EB=A6=84=EC=9D=84=20cos?= =?UTF-8?q?t=20->=20requiredTime=20=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/Application.java | 14 ++++++------- src/main/java/subway/domain/Section.java | 10 +++++----- .../java/subway/domain/SectionRepository.java | 20 +++++++++---------- .../java/subway/screen/FeatureScreen.java | 2 +- src/main/java/subway/view/OutputView.java | 1 + 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/main/java/subway/Application.java b/src/main/java/subway/Application.java index 5dba4eed8..4a06e12fb 100644 --- a/src/main/java/subway/Application.java +++ b/src/main/java/subway/Application.java @@ -42,13 +42,13 @@ private static void initialize() { SectionRepository.addSection("3ํ˜ธ์„ ", "์–‘์žฌ์—ญ", 2); SectionRepository.addSection("์‹ ๋ถ„๋‹น์„ ", "์–‘์žฌ์—ญ", 1); - SectionRepository.addSectinonDistanceAndCost("๊ต๋Œ€์—ญ", "๊ฐ•๋‚จ์—ญ", 2, 3); - SectionRepository.addSectinonDistanceAndCost("๊ฐ•๋‚จ์—ญ", "์—ญ์‚ผ์—ญ", 2, 3); - SectionRepository.addSectinonDistanceAndCost("๊ต๋Œ€์—ญ", "๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ", 3, 2); - SectionRepository.addSectinonDistanceAndCost("๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ", "์–‘์žฌ์—ญ", 6, 5); - SectionRepository.addSectinonDistanceAndCost("์–‘์žฌ์—ญ", "๋งค๋ด‰์—ญ", 1, 1); - SectionRepository.addSectinonDistanceAndCost("๊ฐ•๋‚จ์—ญ", "์–‘์žฌ์—ญ", 2, 8); - SectionRepository.addSectinonDistanceAndCost("์–‘์žฌ์—ญ", "์–‘์žฌ์‹œ๋ฏผ์˜์ˆฒ์—ญ", 10, 3); + SectionRepository.addSectinonDistanceAndTime("๊ต๋Œ€์—ญ", "๊ฐ•๋‚จ์—ญ", 2, 3); + SectionRepository.addSectinonDistanceAndTime("๊ฐ•๋‚จ์—ญ", "์—ญ์‚ผ์—ญ", 2, 3); + SectionRepository.addSectinonDistanceAndTime("๊ต๋Œ€์—ญ", "๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ", 3, 2); + SectionRepository.addSectinonDistanceAndTime("๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ", "์–‘์žฌ์—ญ", 6, 5); + SectionRepository.addSectinonDistanceAndTime("์–‘์žฌ์—ญ", "๋งค๋ด‰์—ญ", 1, 1); + SectionRepository.addSectinonDistanceAndTime("๊ฐ•๋‚จ์—ญ", "์–‘์žฌ์—ญ", 2, 8); + SectionRepository.addSectinonDistanceAndTime("์–‘์žฌ์—ญ", "์–‘์žฌ์‹œ๋ฏผ์˜์ˆฒ์—ญ", 10, 3); } } diff --git a/src/main/java/subway/domain/Section.java b/src/main/java/subway/domain/Section.java index e1270705c..aed82e2f8 100644 --- a/src/main/java/subway/domain/Section.java +++ b/src/main/java/subway/domain/Section.java @@ -8,13 +8,13 @@ public class Section { private Set stations = new HashSet<>(); private int distance; - private int costTime; + private int requiredTime; - public Section(String station1, String station2, int distance, int costTime) { + public Section(String station1, String station2, int distance, int requiredTime) { stations.add(station1); stations.add(station2); this.distance = distance; - this.costTime = costTime; + this.requiredTime = requiredTime; } public boolean isInShortestPath(List shortestPath) { @@ -34,7 +34,7 @@ public int getDistance() { return distance; } - public int getCostTime() { - return costTime; + public int getRequiredTime() { + return requiredTime; } } diff --git a/src/main/java/subway/domain/SectionRepository.java b/src/main/java/subway/domain/SectionRepository.java index ccb61936a..0bc4cf324 100644 --- a/src/main/java/subway/domain/SectionRepository.java +++ b/src/main/java/subway/domain/SectionRepository.java @@ -21,15 +21,15 @@ public static void addSection(String lineName, String stationName, int sequence) line.addSection(sequence, station); } - public static void addSectinonDistanceAndCost(String station1, String station2, int distance, int cost) { + public static void addSectinonDistanceAndTime(String station1, String station2, int distance, int requiredTime) { addVertex(station1, station2); - setEdgeWeight(station1, station2, distance, cost); - sections.add(new Section(station1, station2, distance, cost)); + setEdgeWeight(station1, station2, distance, requiredTime); + sections.add(new Section(station1, station2, distance, requiredTime)); } - private static void setEdgeWeight(String station1, String station2, int distance, int cost) { + private static void setEdgeWeight(String station1, String station2, int distance, int requiredTime) { graphByDistance.setEdgeWeight(graphByDistance.addEdge(station1, station2), distance); - graphByCost.setEdgeWeight(graphByCost.addEdge(station1, station2), cost); + graphByCost.setEdgeWeight(graphByCost.addEdge(station1, station2), requiredTime); } public static void findShortestPathByDistance(String departure, String destination) { @@ -39,8 +39,8 @@ public static void findShortestPathByDistance(String departure, String destinati GraphPath graphPath = dijkstraShortestPath.getPath(departure, destination); List shortestPath = graphPath.getVertexList(); int shortestPathDistance = (int)graphPath.getWeight(); - int costTime = calculateCostTime(shortestPath); - OutputView.printRouteResult(shortestPath, shortestPathDistance, costTime); + int requiredTime = calculateRequiredTime(shortestPath); + OutputView.printRouteResult(shortestPath, shortestPathDistance, requiredTime); } private static void validateDepartureAndDestination(String departure, String destination) { @@ -52,14 +52,14 @@ private static void validateDepartureAndDestination(String departure, String des } - private static int calculateCostTime(List shortestPath) { + private static int calculateRequiredTime(List shortestPath) { return sections.stream() .filter(section -> section.isInShortestPath(shortestPath)) - .mapToInt(Section::getCostTime) + .mapToInt(Section::getRequiredTime) .sum(); } - public static void findShortestPathByCostTime(String departure, String destination) { + public static void findShortestPathByRequiredTime(String departure, String destination) { } diff --git a/src/main/java/subway/screen/FeatureScreen.java b/src/main/java/subway/screen/FeatureScreen.java index 4e8cd4ffb..f65a333e3 100644 --- a/src/main/java/subway/screen/FeatureScreen.java +++ b/src/main/java/subway/screen/FeatureScreen.java @@ -27,7 +27,7 @@ public String showScreen() { } if (input.equals(Menu.ROUTE_CRITERIA.SHORTEST_TIME.getCode())) { - SectionRepository.findShortestPathByCostTime(departure, destination); + SectionRepository.findShortestPathByRequiredTime(departure, destination); } return GO_MAIN; diff --git a/src/main/java/subway/view/OutputView.java b/src/main/java/subway/view/OutputView.java index 7ec1e9476..0dcdc2ad5 100644 --- a/src/main/java/subway/view/OutputView.java +++ b/src/main/java/subway/view/OutputView.java @@ -29,6 +29,7 @@ public static void printRouteResult() { } public static void printRouteResult(List shortestPath, int shortestPathDistance, int costTime) { + System.out.println(); System.out.println("## ์กฐํšŒ ๊ฒฐ๊ณผ"); System.out.println("[INFO] ---"); System.out.println(String.format("์ด ๊ฑฐ๋ฆฌ: %dkm", shortestPathDistance)); From 6cd3836e16ee9970d1ff724bfddaecfb3d528568 Mon Sep 17 00:00:00 2001 From: soongjamm Date: Mon, 21 Dec 2020 10:07:30 +0900 Subject: [PATCH 23/24] =?UTF-8?q?feat:=20=EC=8B=9C=EA=B0=84=EA=B8=B0?= =?UTF-8?q?=EC=A4=80=20=EC=B5=9C=EB=8B=A8=EA=B1=B0=EB=A6=AC=20=EC=B0=BE?= =?UTF-8?q?=EA=B8=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/domain/SectionRepository.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/subway/domain/SectionRepository.java b/src/main/java/subway/domain/SectionRepository.java index 0bc4cf324..d430ffd51 100644 --- a/src/main/java/subway/domain/SectionRepository.java +++ b/src/main/java/subway/domain/SectionRepository.java @@ -60,7 +60,21 @@ private static int calculateRequiredTime(List shortestPath) { } public static void findShortestPathByRequiredTime(String departure, String destination) { + validateDepartureAndDestination(departure, destination); + + DijkstraShortestPath dijkstraShortestPath = new DijkstraShortestPath(graphByCost); + GraphPath graphPath = dijkstraShortestPath.getPath(departure, destination); + List shortestPath = graphPath.getVertexList(); + int shortestPathRequiredTime = (int)graphPath.getWeight(); + int distance = calculateDistance(shortestPath); + OutputView.printRouteResult(shortestPath, distance, shortestPathRequiredTime); + } + private static int calculateDistance(List shortestPath) { + return sections.stream() + .filter(section -> section.isInShortestPath(shortestPath)) + .mapToInt(Section::getDistance) + .sum(); } private static void addVertex(String station1, String station2) { From 22f0cfcd0968bdd8d49308f5c6ee1bd6bfb07f0b Mon Sep 17 00:00:00 2001 From: soongjamm Date: Mon, 21 Dec 2020 15:03:40 +0900 Subject: [PATCH 24/24] =?UTF-8?q?feat(PathResult):=20=EA=B2=BD=EB=A1=9C=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=20=EA=B2=B0=EA=B3=BC=EB=A5=BC=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=ED=95=98=EB=8A=94=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/Menu/Menu.java | 2 +- src/main/java/subway/PathResult.java | 27 +++++++++++++ .../java/subway/domain/SectionRepository.java | 40 +++++++++---------- .../java/subway/screen/FeatureScreen.java | 14 +++---- src/main/java/subway/view/InputView.java | 2 + src/main/java/subway/view/OutputView.java | 14 ++++--- 6 files changed, 64 insertions(+), 35 deletions(-) create mode 100644 src/main/java/subway/PathResult.java diff --git a/src/main/java/subway/Menu/Menu.java b/src/main/java/subway/Menu/Menu.java index 58dc1d440..05467cdbc 100644 --- a/src/main/java/subway/Menu/Menu.java +++ b/src/main/java/subway/Menu/Menu.java @@ -23,7 +23,7 @@ public String getKorean() { } public enum ROUTE_CRITERIA { - SHORTEST_PATH("1", "์ตœ๋‹จ ๊ฑฐ๋ฆฌ"), + SHORTEST_DISTANCE("1", "์ตœ๋‹จ ๊ฑฐ๋ฆฌ"), SHORTEST_TIME("2", "์ตœ์†Œ ์‹œ๊ฐ„"), BACK("B", "๋Œ์•„๊ฐ€๊ธฐ"); diff --git a/src/main/java/subway/PathResult.java b/src/main/java/subway/PathResult.java new file mode 100644 index 000000000..fa40092b0 --- /dev/null +++ b/src/main/java/subway/PathResult.java @@ -0,0 +1,27 @@ +package subway; + +import java.util.List; + +public class PathResult { + List shortestPath; + int distance; + int requiredTime; + + public PathResult(List shortestPath, int distance, int requiredTime) { + this.shortestPath = shortestPath; + this.distance = distance; + this.requiredTime = requiredTime; + } + + public List getShortestPath() { + return shortestPath; + } + + public int getDistance() { + return distance; + } + + public int getRequiredTime() { + return requiredTime; + } +} diff --git a/src/main/java/subway/domain/SectionRepository.java b/src/main/java/subway/domain/SectionRepository.java index d430ffd51..0417a1d08 100644 --- a/src/main/java/subway/domain/SectionRepository.java +++ b/src/main/java/subway/domain/SectionRepository.java @@ -4,7 +4,8 @@ import org.jgrapht.alg.shortestpath.DijkstraShortestPath; import org.jgrapht.graph.DefaultWeightedEdge; import org.jgrapht.graph.WeightedMultigraph; -import subway.view.OutputView; +import subway.Menu.Menu; +import subway.PathResult; import java.util.ArrayList; import java.util.List; @@ -32,26 +33,36 @@ private static void setEdgeWeight(String station1, String station2, int distance graphByCost.setEdgeWeight(graphByCost.addEdge(station1, station2), requiredTime); } - public static void findShortestPathByDistance(String departure, String destination) { + public static PathResult findshortestPath(String input, String departure, String destination) { validateDepartureAndDestination(departure, destination); - DijkstraShortestPath dijkstraShortestPath = new DijkstraShortestPath(graphByDistance); + WeightedMultigraph graph = null; + if (input.equals(Menu.ROUTE_CRITERIA.SHORTEST_DISTANCE.getCode())) { + graph = graphByDistance; + } + if (input.equals(Menu.ROUTE_CRITERIA.SHORTEST_TIME.getCode())) { + graph = graphByCost; + } + List shortestPath = getShortestPath(graph, departure, destination); + + return new PathResult(shortestPath, calculateDistance(shortestPath), calculateRequiredTime(shortestPath)); + } + + public static List getShortestPath(WeightedMultigraph graph, String departure, String destination) { + DijkstraShortestPath dijkstraShortestPath = new DijkstraShortestPath(graph); GraphPath graphPath = dijkstraShortestPath.getPath(departure, destination); - List shortestPath = graphPath.getVertexList(); - int shortestPathDistance = (int)graphPath.getWeight(); - int requiredTime = calculateRequiredTime(shortestPath); - OutputView.printRouteResult(shortestPath, shortestPathDistance, requiredTime); + return graphPath.getVertexList(); + } private static void validateDepartureAndDestination(String departure, String destination) { StationRepository.findStation(departure); StationRepository.deleteStation(destination); if (departure.equals(destination)) { - throw new IllegalArgumentException("[ERROR] ์ถœ๋ฐœ์—ญ๊ณผ ๋„์ฐฉ์—ญ์ด ๊ฐ™์Šต๋‹ˆ๋‹ค."); + throw new IllegalArgumentException("[ERROR] ์ถœ๋ฐœ์—ญ๊ณผ ๋„์ฐฉ์—ญ์ด ๊ฐ™์Šต๋‹ˆ๋‹ค."); } } - private static int calculateRequiredTime(List shortestPath) { return sections.stream() .filter(section -> section.isInShortestPath(shortestPath)) @@ -59,17 +70,6 @@ private static int calculateRequiredTime(List shortestPath) { .sum(); } - public static void findShortestPathByRequiredTime(String departure, String destination) { - validateDepartureAndDestination(departure, destination); - - DijkstraShortestPath dijkstraShortestPath = new DijkstraShortestPath(graphByCost); - GraphPath graphPath = dijkstraShortestPath.getPath(departure, destination); - List shortestPath = graphPath.getVertexList(); - int shortestPathRequiredTime = (int)graphPath.getWeight(); - int distance = calculateDistance(shortestPath); - OutputView.printRouteResult(shortestPath, distance, shortestPathRequiredTime); - } - private static int calculateDistance(List shortestPath) { return sections.stream() .filter(section -> section.isInShortestPath(shortestPath)) diff --git a/src/main/java/subway/screen/FeatureScreen.java b/src/main/java/subway/screen/FeatureScreen.java index f65a333e3..fc003f153 100644 --- a/src/main/java/subway/screen/FeatureScreen.java +++ b/src/main/java/subway/screen/FeatureScreen.java @@ -1,11 +1,13 @@ package subway.screen; -import subway.domain.SectionRepository; -import subway.Menu.Menu; +import subway.PathResult; import subway.view.InputView; +import subway.view.OutputView; import java.util.Scanner; +import static subway.domain.SectionRepository.*; + public class FeatureScreen implements ScreenModel { private final Scanner scanner; @@ -21,14 +23,10 @@ public String showScreen() { InputView inputView = new InputView(scanner); String departure = inputView.enterDeparture(); String destination = inputView.enterDestination(); + PathResult pathResult = findshortestPath(input, departure, destination); + OutputView.printRouteResult(pathResult); - if (input.equals(Menu.ROUTE_CRITERIA.SHORTEST_PATH.getCode())) { - SectionRepository.findShortestPathByDistance(departure, destination); - } - if (input.equals(Menu.ROUTE_CRITERIA.SHORTEST_TIME.getCode())) { - SectionRepository.findShortestPathByRequiredTime(departure, destination); - } return GO_MAIN; } diff --git a/src/main/java/subway/view/InputView.java b/src/main/java/subway/view/InputView.java index 6a49f3f60..0ca9b7d96 100644 --- a/src/main/java/subway/view/InputView.java +++ b/src/main/java/subway/view/InputView.java @@ -16,11 +16,13 @@ public String enterFeature() { } public String enterDeparture() { + System.out.println(); System.out.println("## ์ถœ๋ฐœ์—ญ์„ ์ž…๋ ฅํ•˜์„ธ์š”."); return scanner.nextLine(); } public String enterDestination() { + System.out.println(); System.out.println("## ๋„์ฐฉ์—ญ์„ ์ž…๋ ฅํ•˜์„ธ์š”."); return scanner.nextLine(); } diff --git a/src/main/java/subway/view/OutputView.java b/src/main/java/subway/view/OutputView.java index 0dcdc2ad5..05167b51a 100644 --- a/src/main/java/subway/view/OutputView.java +++ b/src/main/java/subway/view/OutputView.java @@ -1,6 +1,7 @@ package subway.view; import subway.Menu.Menu; +import subway.PathResult; import java.util.List; @@ -24,18 +25,19 @@ public static void printCriteriaMenu() { System.out.println(message); } - public static void printRouteResult() { + public static void printRouteResult(PathResult pathResult) { + List shortestPath = pathResult.getShortestPath(); + int shortestPathDistance = pathResult.getDistance(); + int requiredTime = pathResult.getRequiredTime(); - } - - public static void printRouteResult(List shortestPath, int shortestPathDistance, int costTime) { System.out.println(); System.out.println("## ์กฐํšŒ ๊ฒฐ๊ณผ"); System.out.println("[INFO] ---"); - System.out.println(String.format("์ด ๊ฑฐ๋ฆฌ: %dkm", shortestPathDistance)); - System.out.println(String.format("์ด ์†Œ์š”์‹œ๊ฐ„: %d๋ถ„", costTime)); + System.out.println(String.format("[INFO] ์ด ๊ฑฐ๋ฆฌ: %dkm", shortestPathDistance)); + System.out.println(String.format("[INFO] ์ด ์†Œ์š”์‹œ๊ฐ„: %d๋ถ„", requiredTime)); System.out.println("[INFO] ---"); shortestPath.stream() .forEach(station -> System.out.println("[INFO] " + station)); + System.out.println(); } }