From 1d098837feef8ef40c0ddd6e241cfa93ffd0ffbd Mon Sep 17 00:00:00 2001 From: wndjs803 Date: Sun, 12 May 2024 22:06:53 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=EC=97=AD=20=EA=B4=80=EB=A6=AC=20?= =?UTF-8?q?=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 --- src/main/java/subway/Application.java | 11 +++- .../subway/controller/MainController.java | 30 +++++++++ src/main/java/subway/domain/LineService.java | 4 ++ .../java/subway/domain/StationController.java | 63 +++++++++++++++++++ .../java/subway/domain/StationRepository.java | 5 ++ src/main/java/subway/view/InputView.java | 21 +++++++ src/main/java/subway/view/OutputView.java | 28 +++++++++ 7 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 src/main/java/subway/controller/MainController.java create mode 100644 src/main/java/subway/domain/LineService.java create mode 100644 src/main/java/subway/domain/StationController.java create mode 100644 src/main/java/subway/view/InputView.java create mode 100644 src/main/java/subway/view/OutputView.java diff --git a/src/main/java/subway/Application.java b/src/main/java/subway/Application.java index 0bcf786cc..dbfb6ee54 100644 --- a/src/main/java/subway/Application.java +++ b/src/main/java/subway/Application.java @@ -1,10 +1,17 @@ package subway; +import com.sun.tools.javac.Main; +import subway.controller.MainController; +import subway.domain.Station; +import subway.domain.StationRepository; + +import java.util.List; import java.util.Scanner; + public class Application { public static void main(String[] args) { - final Scanner scanner = new Scanner(System.in); - // TODO: 프로그램 구현 + MainController mainController = new MainController(); + mainController.run(); } } diff --git a/src/main/java/subway/controller/MainController.java b/src/main/java/subway/controller/MainController.java new file mode 100644 index 000000000..54f32f9cd --- /dev/null +++ b/src/main/java/subway/controller/MainController.java @@ -0,0 +1,30 @@ +package subway.controller; + +import subway.domain.StationController; +import subway.view.InputView; +import subway.view.OutputView; + +import java.util.Scanner; + +public class MainController { + private final OutputView outputView; + private final InputView inputView; + private final StationController stationController; + + public MainController() { + outputView = new OutputView(); + inputView = new InputView(); + stationController = new StationController(outputView, inputView); + } + + public void run(){ + while (true){ + outputView.mainPage(); + String input = inputView.selectFunction(); + + if(input.equals("1")){ + stationController.manage(); + } + } + } +} diff --git a/src/main/java/subway/domain/LineService.java b/src/main/java/subway/domain/LineService.java new file mode 100644 index 000000000..af96adebd --- /dev/null +++ b/src/main/java/subway/domain/LineService.java @@ -0,0 +1,4 @@ +package subway.domain; + +public class LineService { +} diff --git a/src/main/java/subway/domain/StationController.java b/src/main/java/subway/domain/StationController.java new file mode 100644 index 000000000..73c12768e --- /dev/null +++ b/src/main/java/subway/domain/StationController.java @@ -0,0 +1,63 @@ +package subway.domain; + +import subway.view.InputView; +import subway.view.OutputView; + +public class StationController { + private final OutputView outputView; + private final InputView inputView; + + public StationController(OutputView outputView, InputView inputView) { + this.outputView = outputView; + this.inputView = inputView; + } + + public void manage(){ + outputView.stationManagementPage(); + String input = inputView.selectFunction(); + + if(input.equals("1")){ + registerStation(); + return; + } + if(input.equals("2")){ + deleteStation(); + return; + } + if(input.equals("3")){ + listStation(); + return; + } + if(input.equals("B")) return; + } + + private void registerStation(){ + String stationName = inputView.inputRegisterStation(); + + if(stationName.length() < 2){ + System.out.println("두글자 이상"); + return; + } + if(StationRepository.isExist(stationName)){ + System.out.println("이미 존재하는 역"); + return; + } + + StationRepository.addStation(new Station(stationName)); + outputView.registeredStation(); + } + + private void deleteStation(){ + String stationName = inputView.inputDeleteStation(); + if(!StationRepository.deleteStation(stationName)){ + System.out.println("삭제 실패"); + } + outputView.deletedStation(); + } + + private void listStation(){ + StationRepository.stations().stream() + .map(Station::getName) + .forEach(System.out::println); + } +} diff --git a/src/main/java/subway/domain/StationRepository.java b/src/main/java/subway/domain/StationRepository.java index b7245c0f3..7af98bb27 100644 --- a/src/main/java/subway/domain/StationRepository.java +++ b/src/main/java/subway/domain/StationRepository.java @@ -19,4 +19,9 @@ public static void addStation(Station station) { public static boolean deleteStation(String name) { return stations.removeIf(station -> Objects.equals(station.getName(), name)); } + + public static boolean isExist(String name) { + return stations.stream() + .anyMatch(station -> station.getName().equals(name)); + } } diff --git a/src/main/java/subway/view/InputView.java b/src/main/java/subway/view/InputView.java new file mode 100644 index 000000000..705e1b3b2 --- /dev/null +++ b/src/main/java/subway/view/InputView.java @@ -0,0 +1,21 @@ +package subway.view; + +import java.util.Scanner; + +public class InputView { + private final Scanner scanner = new Scanner(System.in); + public String selectFunction(){ + System.out.println("## 원하는 기능을 선택하세요"); + return scanner.nextLine(); + } + + public String inputRegisterStation(){ + System.out.println("## 등록할 역 이름을 입력하세요."); + return scanner.nextLine(); + } + + public String inputDeleteStation(){ + System.out.println("## 삭제할 역 이름을 입력하세요."); + return scanner.nextLine(); + } +} diff --git a/src/main/java/subway/view/OutputView.java b/src/main/java/subway/view/OutputView.java new file mode 100644 index 000000000..3327f78a7 --- /dev/null +++ b/src/main/java/subway/view/OutputView.java @@ -0,0 +1,28 @@ +package subway.view; + +public class OutputView { + public void mainPage(){ + System.out.println("## 메인 화면\n" + + "1. 역 관리\n" + + "2. 노선 관리\n" + + "3. 구간 관리\n" + + "4. 지하철 노선도 출력\n" + + "Q. 종료\n"); + } + + public void stationManagementPage(){ + System.out.println("## 역 관리 화면\n" + + "1. 역 등록\n" + + "2. 역 삭제\n" + + "3. 역 조회\n" + + "B. 돌아가기\n"); + } + + public void registeredStation(){ + System.out.println("[INFO] 지하철 역이 등록되었습니다.\n"); + } + + public void deletedStation(){ + System.out.println("[INFO] 지하철 역이 삭제되었습니다.\n"); + } +} From 31eb65c8b05f7618261f31ad7e6791a793af6d58 Mon Sep 17 00:00:00 2001 From: wndjs803 Date: Sun, 12 May 2024 23:38:01 +0900 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20=EB=85=B8=EC=84=A0=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=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 --- .../subway/controller/MainController.java | 9 ++ .../java/subway/domain/LineController.java | 87 +++++++++++++++++++ src/main/java/subway/domain/LineService.java | 4 - .../java/subway/domain/StationController.java | 2 +- src/main/java/subway/domain/Subway.java | 10 +++ src/main/java/subway/view/InputView.java | 20 +++++ src/main/java/subway/view/OutputView.java | 16 ++++ 7 files changed, 143 insertions(+), 5 deletions(-) create mode 100644 src/main/java/subway/domain/LineController.java delete mode 100644 src/main/java/subway/domain/LineService.java create mode 100644 src/main/java/subway/domain/Subway.java diff --git a/src/main/java/subway/controller/MainController.java b/src/main/java/subway/controller/MainController.java index 54f32f9cd..ff4e43b9f 100644 --- a/src/main/java/subway/controller/MainController.java +++ b/src/main/java/subway/controller/MainController.java @@ -1,5 +1,6 @@ package subway.controller; +import subway.domain.LineController; import subway.domain.StationController; import subway.view.InputView; import subway.view.OutputView; @@ -10,11 +11,13 @@ public class MainController { private final OutputView outputView; private final InputView inputView; private final StationController stationController; + private final LineController lineController; public MainController() { outputView = new OutputView(); inputView = new InputView(); stationController = new StationController(outputView, inputView); + lineController = new LineController(outputView, inputView); } public void run(){ @@ -24,7 +27,13 @@ public void run(){ if(input.equals("1")){ stationController.manage(); + continue; } + if(input.equals("2")){ + lineController.manage(); + continue; + } + } } } diff --git a/src/main/java/subway/domain/LineController.java b/src/main/java/subway/domain/LineController.java new file mode 100644 index 000000000..ff2bf46f6 --- /dev/null +++ b/src/main/java/subway/domain/LineController.java @@ -0,0 +1,87 @@ +package subway.domain; + +import subway.view.InputView; +import subway.view.OutputView; + +import java.util.ArrayList; +import java.util.List; + +public class LineController { + private final OutputView outputView; + private final InputView inputView; + + public LineController(OutputView outputView, InputView inputView) { + this.outputView = outputView; + this.inputView = inputView; + } + + public void manage(){ + outputView.lineManagementPage(); + String input = inputView.selectFunction(); + + if(input.equals("1")){ + registerLine(); + return; + } + if(input.equals("2")){ + deleteLine(); + return; + } + if(input.equals("3")){ + listLines(); + return; + } + if(input.equals("B")) return; + } + + private void registerLine(){ + String lineName = inputView.inputRegisterLine(); + String startStationName = inputView.inputStartStation(); + String endStationName = inputView.inputEndStation(); + + if(lineName.length() < 2){ + System.out.println("두 글자 이상"); + return; + } + Line line = new Line(lineName); + + if(Subway.lines.containsKey(line)){ + System.out.println("이미 존재하는 노선"); + } + if(!StationRepository.isExist(startStationName)){ + System.out.println("존재하지 않는 역"); + return; + } + if(!StationRepository.isExist(endStationName)){ + System.out.println("존재하지 않는 역"); + return; + } + + LineRepository.addLine(line); + + List stations = new ArrayList<>(); + stations.add(new Station(startStationName)); + stations.add(new Station(endStationName)); + + Subway.lines.put(line, stations); + outputView.registeredLine(); + } + + public void deleteLine(){ + String stationName = inputView.inputDeleteLine(); + if(!LineRepository.deleteLineByName(stationName)){ + System.out.println("존재하지 않는 노선"); + return; + } + Line line = new Line(stationName); + Subway.lines.remove(line); + outputView.deletedLine(); + } + + public void listLines(){ + LineRepository.lines().stream() + .map(Line::getName) + .forEach(name -> System.out.println("[INFO} " + name)); + } + +} diff --git a/src/main/java/subway/domain/LineService.java b/src/main/java/subway/domain/LineService.java deleted file mode 100644 index af96adebd..000000000 --- a/src/main/java/subway/domain/LineService.java +++ /dev/null @@ -1,4 +0,0 @@ -package subway.domain; - -public class LineService { -} diff --git a/src/main/java/subway/domain/StationController.java b/src/main/java/subway/domain/StationController.java index 73c12768e..d5e735f99 100644 --- a/src/main/java/subway/domain/StationController.java +++ b/src/main/java/subway/domain/StationController.java @@ -58,6 +58,6 @@ private void deleteStation(){ private void listStation(){ StationRepository.stations().stream() .map(Station::getName) - .forEach(System.out::println); + .forEach(name -> System.out.println("[INFO] " + name)); } } diff --git a/src/main/java/subway/domain/Subway.java b/src/main/java/subway/domain/Subway.java new file mode 100644 index 000000000..c68e43525 --- /dev/null +++ b/src/main/java/subway/domain/Subway.java @@ -0,0 +1,10 @@ +package subway.domain; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Subway { + public static Map> lines = new HashMap<>(); + +} diff --git a/src/main/java/subway/view/InputView.java b/src/main/java/subway/view/InputView.java index 705e1b3b2..0043b83e7 100644 --- a/src/main/java/subway/view/InputView.java +++ b/src/main/java/subway/view/InputView.java @@ -18,4 +18,24 @@ public String inputDeleteStation(){ System.out.println("## 삭제할 역 이름을 입력하세요."); return scanner.nextLine(); } + + public String inputRegisterLine(){ + System.out.println("## 등록할 노선 이름을 입력하세요."); + return scanner.nextLine(); + } + + public String inputStartStation(){ + System.out.println("## 등록할 노선의 상행 종점역 이름을 입력하세요."); + return scanner.nextLine(); + } + + public String inputEndStation(){ + System.out.println("## 등록할 노선의 하행 종점역 이름을 입력하세요."); + return scanner.nextLine(); + } + + public String inputDeleteLine(){ + 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 3327f78a7..41746bf51 100644 --- a/src/main/java/subway/view/OutputView.java +++ b/src/main/java/subway/view/OutputView.java @@ -25,4 +25,20 @@ public void registeredStation(){ public void deletedStation(){ System.out.println("[INFO] 지하철 역이 삭제되었습니다.\n"); } + + public void lineManagementPage(){ + System.out.println("## 노선 관리 화면\n" + + "1. 노선 등록\n" + + "2. 노선 삭제\n" + + "3. 노선 조회\n" + + "B. 돌아가기\n"); + } + + public void registeredLine(){ + System.out.println("[INFO] 지하철 노선이 등록되었습니다."); + } + + public void deletedLine(){ + System.out.println("[INFO] 지하철 노선이 삭제되었습니다."); + } } From 77873fc38ce18b8c766ce3e10ee72ae06026f581 Mon Sep 17 00:00:00 2001 From: wndjs803 Date: Mon, 13 May 2024 00:12:39 +0900 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20=EA=B5=AC=EA=B0=84=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=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 --- .../subway/controller/MainController.java | 18 +++-- .../java/subway/domain/LineRepository.java | 5 ++ .../{LineController.java => LineService.java} | 4 +- .../java/subway/domain/SectionService.java | 68 +++++++++++++++++++ ...ionController.java => StationService.java} | 4 +- src/main/java/subway/view/InputView.java | 25 +++++++ src/main/java/subway/view/OutputView.java | 19 +++++- 7 files changed, 127 insertions(+), 16 deletions(-) rename src/main/java/subway/domain/{LineController.java => LineService.java} (95%) create mode 100644 src/main/java/subway/domain/SectionService.java rename src/main/java/subway/domain/{StationController.java => StationService.java} (93%) diff --git a/src/main/java/subway/controller/MainController.java b/src/main/java/subway/controller/MainController.java index ff4e43b9f..bd8a67cb5 100644 --- a/src/main/java/subway/controller/MainController.java +++ b/src/main/java/subway/controller/MainController.java @@ -1,23 +1,21 @@ package subway.controller; -import subway.domain.LineController; -import subway.domain.StationController; +import subway.domain.LineService; +import subway.domain.StationService; import subway.view.InputView; import subway.view.OutputView; -import java.util.Scanner; - public class MainController { private final OutputView outputView; private final InputView inputView; - private final StationController stationController; - private final LineController lineController; + private final StationService stationService; + private final LineService lineService; public MainController() { outputView = new OutputView(); inputView = new InputView(); - stationController = new StationController(outputView, inputView); - lineController = new LineController(outputView, inputView); + stationService = new StationService(outputView, inputView); + lineService = new LineService(outputView, inputView); } public void run(){ @@ -26,11 +24,11 @@ public void run(){ String input = inputView.selectFunction(); if(input.equals("1")){ - stationController.manage(); + stationService.manage(); continue; } if(input.equals("2")){ - lineController.manage(); + lineService.manage(); continue; } diff --git a/src/main/java/subway/domain/LineRepository.java b/src/main/java/subway/domain/LineRepository.java index 49132ddb6..f2f7ed9d7 100644 --- a/src/main/java/subway/domain/LineRepository.java +++ b/src/main/java/subway/domain/LineRepository.java @@ -16,6 +16,11 @@ public static void addLine(Line line) { lines.add(line); } + public static boolean isExist(String name) { + return lines().stream() + .anyMatch(station -> station.getName().equals(name)); + } + public static boolean deleteLineByName(String name) { return lines.removeIf(line -> Objects.equals(line.getName(), name)); } diff --git a/src/main/java/subway/domain/LineController.java b/src/main/java/subway/domain/LineService.java similarity index 95% rename from src/main/java/subway/domain/LineController.java rename to src/main/java/subway/domain/LineService.java index ff2bf46f6..d3a25ea8b 100644 --- a/src/main/java/subway/domain/LineController.java +++ b/src/main/java/subway/domain/LineService.java @@ -6,11 +6,11 @@ import java.util.ArrayList; import java.util.List; -public class LineController { +public class LineService { private final OutputView outputView; private final InputView inputView; - public LineController(OutputView outputView, InputView inputView) { + public LineService(OutputView outputView, InputView inputView) { this.outputView = outputView; this.inputView = inputView; } diff --git a/src/main/java/subway/domain/SectionService.java b/src/main/java/subway/domain/SectionService.java new file mode 100644 index 000000000..292e53c2e --- /dev/null +++ b/src/main/java/subway/domain/SectionService.java @@ -0,0 +1,68 @@ +package subway.domain; + +import subway.view.InputView; +import subway.view.OutputView; + +import java.util.List; + + +public class SectionService { + private final OutputView outputView; + private final InputView inputView; + + public SectionService(OutputView outputView, InputView inputView) { + this.outputView = outputView; + this.inputView = inputView; + } + + public void manage(){ + outputView.sectionManagementPage(); + String input = inputView.selectFunction(); + + if(input.equals("1")){ + registerSection(); + return; + } + } + + private void registerSection(){ + String line = inputView.inputLineToRegisterSection(); + String station = inputView.inputStationToRegisterSection(); + int order = Integer.parseInt(inputView.inputOrder()); + + if(!LineRepository.isExist(line)){ + System.out.println("존재하지 않는 노선"); + return; + } + if(!StationRepository.isExist(station)){ + System.out.println("존재하지 않는 역"); + return; + } + + List stations = Subway.lines.get(line); + if(stations.contains(new Station(station))){ + System.out.println("이미 존재하는 역"); + } + + stations.add(order, new Station(station)); + outputView.registeredSection(); + } + + private void deleteSection(){ + String line = inputView.inputDeleteLineOfSection(); + String station = inputView.inputDeleteStationOfSection(); + + if(!LineRepository.isExist(line)){ + System.out.println("존재하지 않는 노선"); + return; + } + if(!StationRepository.isExist(station)){ + System.out.println("존재하지 않는 역"); + return; + } + + List stations = Subway.lines.get(line); + stations.remove(new Station(station)); + + } +} diff --git a/src/main/java/subway/domain/StationController.java b/src/main/java/subway/domain/StationService.java similarity index 93% rename from src/main/java/subway/domain/StationController.java rename to src/main/java/subway/domain/StationService.java index d5e735f99..b3e1a02f9 100644 --- a/src/main/java/subway/domain/StationController.java +++ b/src/main/java/subway/domain/StationService.java @@ -3,11 +3,11 @@ import subway.view.InputView; import subway.view.OutputView; -public class StationController { +public class StationService { private final OutputView outputView; private final InputView inputView; - public StationController(OutputView outputView, InputView inputView) { + public StationService(OutputView outputView, InputView inputView) { this.outputView = outputView; this.inputView = inputView; } diff --git a/src/main/java/subway/view/InputView.java b/src/main/java/subway/view/InputView.java index 0043b83e7..c3e25f30a 100644 --- a/src/main/java/subway/view/InputView.java +++ b/src/main/java/subway/view/InputView.java @@ -38,4 +38,29 @@ public String inputDeleteLine(){ System.out.println("## 삭제할 노선 이름을 입력하세요."); return scanner.nextLine(); } + + public String inputLineToRegisterSection(){ + System.out.println("## 노선을 입력하세요."); + return scanner.nextLine(); + } + + public String inputStationToRegisterSection(){ + System.out.println("## 역이름을 입력하세요."); + return scanner.nextLine(); + } + + public String inputOrder(){ + System.out.println("## 순서를 입력하세요."); + return scanner.nextLine(); + } + + public String inputDeleteLineOfSection(){ + System.out.println("## 삭제할 구간의 노선을 입력하세요."); + return scanner.nextLine(); + } + + public String inputDeleteStationOfSection(){ + 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 41746bf51..771c88d3c 100644 --- a/src/main/java/subway/view/OutputView.java +++ b/src/main/java/subway/view/OutputView.java @@ -35,10 +35,25 @@ public void lineManagementPage(){ } public void registeredLine(){ - System.out.println("[INFO] 지하철 노선이 등록되었습니다."); + System.out.println("[INFO] 지하철 노선이 등록되었습니다.\n"); } public void deletedLine(){ - System.out.println("[INFO] 지하철 노선이 삭제되었습니다."); + System.out.println("[INFO] 지하철 노선이 삭제되었습니다.\n"); + } + + public void sectionManagementPage(){ + System.out.println("## 구간 관리 화면\n" + + "1. 구간 등록\n" + + "2. 구간 삭제\n" + + "B. 돌아가기\n"); + } + + public void registeredSection(){ + System.out.println("[INFO] 구간이 등록되었습니다.\n"); + } + + public void deletedSection(){ + System.out.println("[INFO] 구간이 삭제되었습니다.\n"); } } From 479f3aad2230a528f594c08bc12c08cfd9f9995e Mon Sep 17 00:00:00 2001 From: wndjs803 Date: Mon, 13 May 2024 00:21:25 +0900 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20=EC=A7=80=ED=95=98=EC=B2=A0=20?= =?UTF-8?q?=EB=85=B8=EC=84=A0=EB=8F=84=20=EC=B6=9C=EB=A0=A5=20=EA=B8=B0?= =?UTF-8?q?=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 --- .../subway/controller/MainController.java | 32 +++++++++++++++++-- .../java/subway/domain/SectionService.java | 4 +++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main/java/subway/controller/MainController.java b/src/main/java/subway/controller/MainController.java index bd8a67cb5..67f37585c 100644 --- a/src/main/java/subway/controller/MainController.java +++ b/src/main/java/subway/controller/MainController.java @@ -1,21 +1,25 @@ package subway.controller; -import subway.domain.LineService; -import subway.domain.StationService; +import subway.domain.*; import subway.view.InputView; import subway.view.OutputView; +import java.util.List; +import java.util.Map; + public class MainController { private final OutputView outputView; private final InputView inputView; private final StationService stationService; private final LineService lineService; + private final SectionService sectionService; public MainController() { outputView = new OutputView(); inputView = new InputView(); stationService = new StationService(outputView, inputView); lineService = new LineService(outputView, inputView); + sectionService = new SectionService(outputView, inputView); } public void run(){ @@ -31,7 +35,31 @@ public void run(){ lineService.manage(); continue; } + if(input.equals("3")){ + sectionService.manage(); + continue; + } + if(input.equals("4")){ + listALl(); + continue; + } + if(input.equals("Q")) return; + + + } + } + + private void listALl(){ + for (Map.Entry> entry : Subway.lines.entrySet()) { + Line line = entry.getKey(); + List stations = entry.getValue(); + + System.out.println("[INFO] " + line.getName()); + for (Station station : stations) { + System.out.println("[INFO}" + station.getName()); + } + System.out.println(); } } } diff --git a/src/main/java/subway/domain/SectionService.java b/src/main/java/subway/domain/SectionService.java index 292e53c2e..0445bb01c 100644 --- a/src/main/java/subway/domain/SectionService.java +++ b/src/main/java/subway/domain/SectionService.java @@ -23,6 +23,10 @@ public void manage(){ registerSection(); return; } + if(input.equals("2")){ + deleteSection(); + } + if(input.equals("B")) return; } private void registerSection(){ From de15d43971f9d6de09269b178159f5007ff135e7 Mon Sep 17 00:00:00 2001 From: wndjs803 Date: Mon, 13 May 2024 00:25:46 +0900 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20error=20=EB=A9=94=EC=84=B8=EC=A7=80?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/subway/controller/MainController.java | 14 +------------- src/main/java/subway/domain/LineService.java | 14 ++++++++++++++ src/main/java/subway/domain/SectionService.java | 12 ++++++------ src/main/java/subway/domain/StationService.java | 6 +++--- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/main/java/subway/controller/MainController.java b/src/main/java/subway/controller/MainController.java index 67f37585c..31bcce571 100644 --- a/src/main/java/subway/controller/MainController.java +++ b/src/main/java/subway/controller/MainController.java @@ -40,7 +40,7 @@ public void run(){ continue; } if(input.equals("4")){ - listALl(); + lineService.listALl(); continue; } if(input.equals("Q")) return; @@ -49,17 +49,5 @@ public void run(){ } } - private void listALl(){ - for (Map.Entry> entry : Subway.lines.entrySet()) { - Line line = entry.getKey(); - List stations = entry.getValue(); - System.out.println("[INFO] " + line.getName()); - for (Station station : stations) { - System.out.println("[INFO}" + station.getName()); - } - - System.out.println(); - } - } } diff --git a/src/main/java/subway/domain/LineService.java b/src/main/java/subway/domain/LineService.java index d3a25ea8b..43a105c7e 100644 --- a/src/main/java/subway/domain/LineService.java +++ b/src/main/java/subway/domain/LineService.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; public class LineService { private final OutputView outputView; @@ -84,4 +85,17 @@ public void listLines(){ .forEach(name -> System.out.println("[INFO} " + name)); } + public void listALl(){ + for (Map.Entry> entry : Subway.lines.entrySet()) { + Line line = entry.getKey(); + List stations = entry.getValue(); + + System.out.println("[INFO] " + line.getName()); + for (Station station : stations) { + System.out.println("[INFO}" + station.getName()); + } + + System.out.println(); + } + } } diff --git a/src/main/java/subway/domain/SectionService.java b/src/main/java/subway/domain/SectionService.java index 0445bb01c..36f535400 100644 --- a/src/main/java/subway/domain/SectionService.java +++ b/src/main/java/subway/domain/SectionService.java @@ -35,17 +35,17 @@ private void registerSection(){ int order = Integer.parseInt(inputView.inputOrder()); if(!LineRepository.isExist(line)){ - System.out.println("존재하지 않는 노선"); + System.out.println("[ERROR] 존재하지 않는 노선입니다."); return; } if(!StationRepository.isExist(station)){ - System.out.println("존재하지 않는 역"); + System.out.println("[ERROR] 존재하지 않는 역입니다."); return; } List stations = Subway.lines.get(line); if(stations.contains(new Station(station))){ - System.out.println("이미 존재하는 역"); + System.out.println("[ERROR] 이미 존재하는 역입니다."); } stations.add(order, new Station(station)); @@ -57,16 +57,16 @@ private void deleteSection(){ String station = inputView.inputDeleteStationOfSection(); if(!LineRepository.isExist(line)){ - System.out.println("존재하지 않는 노선"); + System.out.println("[ERROR] 존재하지 않는 노선입니다."); return; } if(!StationRepository.isExist(station)){ - System.out.println("존재하지 않는 역"); + System.out.println("[ERROR] 존재하지 않는 역입니다."); return; } List stations = Subway.lines.get(line); stations.remove(new Station(station)); - + outputView.deletedStation(); } } diff --git a/src/main/java/subway/domain/StationService.java b/src/main/java/subway/domain/StationService.java index b3e1a02f9..e9dc9ec85 100644 --- a/src/main/java/subway/domain/StationService.java +++ b/src/main/java/subway/domain/StationService.java @@ -35,11 +35,11 @@ private void registerStation(){ String stationName = inputView.inputRegisterStation(); if(stationName.length() < 2){ - System.out.println("두글자 이상"); + System.out.println("[ERROR] 두 글자 이상 입력해야합니다."); return; } if(StationRepository.isExist(stationName)){ - System.out.println("이미 존재하는 역"); + System.out.println("[ERROR] 존재하는 역입니다."); return; } @@ -50,7 +50,7 @@ private void registerStation(){ private void deleteStation(){ String stationName = inputView.inputDeleteStation(); if(!StationRepository.deleteStation(stationName)){ - System.out.println("삭제 실패"); + System.out.println("[ERROR] 역 삭제에 실패했습니다."); } outputView.deletedStation(); }