Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[지하철 노선도] [팀 주디 활동] 권광재 제출합니다. #7

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 지하철 노선도 미션

## 초기 설정
- [X] #1 교대역, 강남역, 역삼역, 남부터미널역, 양재역, 양재시민의숲역, 매봉역 등록
- [X] #2 지하철 노선으로 2호선, 3호선, 신분당선 등록
- [X] #3 노선에 역 순서 등록
- 2호선: 교대역 - 강남역 - 역삼역
- 3호선: 교대역 - 남부터미널역 - 양재역 - 매봉역
- 신분당선: 강남역 - 양재역 - 양재시민의숲역

## 지하철 역 관련 기능
- [X] #4 지하철 역 등록 및 삭제
- [X] #5 노선에 등록된 역은 삭제 불가
- [X] #6 중복된 지하철 역 이름이 등록 불가
- [X] #7 지하철 역 이름은 2글자 이상
- [X] #8 지하철 역의 목록을 조회 가능

## 지하철 노선 관련 기능
- [X] #9 지하철 노선 등록 및 삭제
- [X] #10 중복된 지하철 노선 이름 등록 불가
- [X] #11 지하철 노선 이름은 2글자 이상
- [X] #12 노선 등록 시 상행 종점역과 하행 종점역 입력 필수
- [X] #13 지하철 노선의 목록을 조회 가능

## 지하철 구간 관련 기능
- [X] #14 하나의 역 여러개의 노선 추가, 삭제 가능
- [X] #15 역과 역 사이에 새로운 역이 추가 가능
- [X] #16 노선에서 갈래길은 불가
- [X] #17 종점 제거 시 다음 역으로 종점 변경
- [X] #18 노선에 포함된 역이 두 개 이하일 경우 역 제거 불가



7 changes: 6 additions & 1 deletion src/main/java/subway/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

import java.util.Scanner;

import subway.common.AppConfig;
import subway.controller.MainController;

public class Application {
public static void main(String[] args) {
final Scanner scanner = new Scanner(System.in);
// TODO: 프로그램 구현
AppConfig appConfig = new AppConfig();
MainController mainController = appConfig.mainController(scanner);
mainController.run();
}
}
47 changes: 47 additions & 0 deletions src/main/java/subway/common/AppConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package subway.common;

import java.util.Scanner;

import subway.controller.LineController;
import subway.controller.MainController;
import subway.controller.SectionController;
import subway.controller.StationController;
import subway.data.DataInitializer;
import subway.domain.LineRepository;
import subway.domain.SectionRepository;
import subway.domain.StationRepository;
import subway.service.LineService;
import subway.service.SectionService;
import subway.service.StationService;
import subway.service.SubwayService;
import subway.view.LineView;
import subway.view.MainView;
import subway.view.SectionView;
import subway.view.StationView;

public class AppConfig {

public MainController mainController(Scanner scanner) {

MainView mainView = new MainView();
StationView stationView = new StationView();
LineView lineView = new LineView();
SectionView sectionView = new SectionView();

StationRepository stationRepository = new StationRepository();
LineRepository lineRepository = new LineRepository();
SectionRepository sectionRepository = new SectionRepository();

StationService stationService = new StationService(stationRepository, sectionRepository);
LineService lineService = new LineService(lineRepository, sectionRepository, stationRepository);
SectionService sectionCapService = new SectionService(lineRepository, sectionRepository, stationRepository);
DataInitializer dataInitializer = new DataInitializer(lineRepository, stationRepository, sectionRepository);
SubwayService subwayService = new SubwayService(dataInitializer);

StationController stationController = new StationController(scanner, stationView, stationService, mainView);
LineController lineController = new LineController(scanner, lineView, lineService, mainView);
SectionController sectionController = new SectionController(scanner, sectionView, sectionCapService, mainView);

return new MainController(scanner, stationController, lineController, sectionController, subwayService, mainView);
}
}
63 changes: 63 additions & 0 deletions src/main/java/subway/controller/LineController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package subway.controller;

import java.util.List;
import java.util.Scanner;

import subway.service.LineService;
import subway.view.LineView;
import subway.view.MainView;
import subway.view.command.CommandLine;

public class LineController {
private final LineView lineView;
private final MainView mainView;
private final LineService lineService;
private final Scanner scanner;

public LineController(Scanner scanner, LineView lineView, LineService lineService, MainView mainView) {
this.scanner = scanner;
this.lineView = lineView;
this.mainView = mainView;
this.lineService = lineService;
}

void manageLine() {
boolean back = true;
while (back) {
lineView.printLineView();
mainView.printSelectView();
String commandInput = scanner.nextLine().trim();
CommandLine command = CommandLine.fromString(commandInput);
if (command.equals(CommandLine.ADD_LINE)) {
lineView.printAddLine();
String lineName = scanner.nextLine().trim();
lineView.printAddFirstLine();
String startStationName = scanner.nextLine().trim();
lineView.printAddLastLine();
String endStationName = scanner.nextLine().trim();
lineService.addLine(lineName, startStationName, endStationName);
lineView.printSuccessAddLine();
}
if (command.equals(CommandLine.DELETE_LINE)) {
lineView.printDeleteLine();
String lineName = scanner.nextLine().trim();
lineService.deleteLine(lineName);
lineView.printSuccessDeleteLine();
}
if (command.equals(CommandLine.VIEW_LINES)) {
lineView.printSelectLine();
List<String> lines = lineService.getLines();
lineView.printLineList(lines);
}
if (command.equals(CommandLine.BACK)) {
back = false;
}
}
}

public void printLine() {
lineService.printAllLinesAndStations();
}


}
66 changes: 66 additions & 0 deletions src/main/java/subway/controller/MainController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package subway.controller;

import java.util.Scanner;

import subway.service.LineService;
import subway.service.SectionService;
import subway.service.StationService;
import subway.service.SubwayService;
import subway.view.LineView;
import subway.view.MainView;
import subway.view.SectionView;
import subway.view.StationView;
import subway.view.command.CommandMain;

public class MainController {
private final StationController stationController;
private final LineController lineController;
private final SectionController sectionController;
private final MainView mainView;
private final Scanner scanner;
private final SubwayService subwayService;


public MainController(Scanner scanner, StationController stationController, LineController lineController,
SectionController sectionController, SubwayService subwayService, MainView mainView
) {
this.scanner = scanner;
this.stationController = stationController;
this.lineController = lineController;
this.sectionController = sectionController;
this.subwayService = subwayService;
this.mainView = mainView;
}

public void run() {
subwayService.settingData();
selectSubway();
}

public void selectSubway() {
boolean quit = true;
while (quit){
mainView.printMainView();
mainView.printSelectView();
String commandInput = scanner.nextLine().trim();
CommandMain command = CommandMain.fromString(commandInput);
if (command.equals(CommandMain.MANAGE_STATION)) {
stationController.manageStation();
}
if (command.equals(CommandMain.MANAGE_LINE)) {
lineController.manageLine();
}
if (command.equals(CommandMain.MANAGE_SECTION)) {
sectionController.manageSection();
}
if (command.equals(CommandMain.PRINT_LINE_MAP)) {
lineController.printLine();
}
if (command.equals(CommandMain.QUIT)) {
quit = false;
}
}
}


}
55 changes: 55 additions & 0 deletions src/main/java/subway/controller/SectionController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package subway.controller;

import java.util.Scanner;

import subway.service.SectionService;
import subway.view.MainView;
import subway.view.SectionView;
import subway.view.command.CommandSection;

public class SectionController {
private final SectionView sectionView;
private final MainView mainView;
private final SectionService sectionService;
private final Scanner scanner;

public SectionController(Scanner scanner, SectionView sectionView, SectionService sectionService, MainView mainView) {
this.scanner = scanner;
this.sectionView = sectionView;
this.mainView = mainView;
this.sectionService = sectionService;
}
public void manageSection() {
boolean back = true;
while (back) {
sectionView.printSectionView();
mainView.printSelectView();
String commandInput = scanner.nextLine().trim();
CommandSection command = CommandSection.fromString(commandInput);
if (command.equals(CommandSection.ADD_SECTION)) {
sectionView.printAddSection();
String lineName = scanner.nextLine().trim();
sectionView.printAddStationName();
String stationName = scanner.nextLine().trim();
sectionView.printAddOrder();
int position = Integer.parseInt(scanner.nextLine().trim());
sectionService.addSection(lineName, stationName, position);
sectionView.printSuccessSectionStation();
}
if (command.equals(CommandSection.DELETE_SECTION)) {
sectionView.printDeleteSection();
String lineName = scanner.nextLine().trim();
sectionView.printDeleteStation();
String stationName = scanner.nextLine().trim();
sectionService.deleteSection(lineName, stationName);
sectionView.printSuccessDeleteSection();
}
if (command.equals(CommandSection.BACK)) {
back = false;
}
}
}


}

55 changes: 55 additions & 0 deletions src/main/java/subway/controller/StationController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package subway.controller;

import java.util.List;
import java.util.Scanner;

import subway.service.StationService;
import subway.view.MainView;
import subway.view.StationView;
import subway.view.command.CommandStation;

public class StationController {
private final StationView stationView;
private final MainView mainView;
private final StationService stationService;
private final Scanner scanner;

public StationController(Scanner scanner, StationView stationView, StationService stationService, MainView mainView) {
this.scanner = scanner;
this.stationView = stationView;
this.mainView = mainView;
this.stationService = stationService;
}

public void manageStation() {
boolean back = true;
while (back) {
stationView.printStationView();
mainView.printSelectView();
String commandInput = scanner.nextLine().trim();
CommandStation command = CommandStation.fromString(commandInput);
if (command.equals(CommandStation.ADD_STATION)) {
stationView.printAddStation();
String stationName = scanner.nextLine().trim();
stationService.addStation(stationName);
stationView.printSuccessAddStation();
}
if (command.equals(CommandStation.DELETE_STATION)) {
stationView.printDeleteStation();
String stationName = scanner.nextLine().trim();
stationService.deleteStation(stationName);
stationView.printSuccessDeleteStation();
}
if (command.equals(CommandStation.VIEW_STATIONS)) {
stationView.printSelectStation();
List<String> stations = stationService.getStations();
stationView.printStationList(stations);
}
if (command.equals(CommandStation.BACK)) {
back = false;
}
}
}


}
47 changes: 47 additions & 0 deletions src/main/java/subway/data/DataInitializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package subway.data;

import java.util.List;
import java.util.Map;

import subway.domain.Line;
import subway.domain.LineRepository;
import subway.domain.Section;
import subway.domain.SectionRepository;
import subway.domain.Station;
import subway.domain.StationRepository;

public class DataInitializer {
private final LineRepository lineRepository;
private final StationRepository stationRepository;
private final SectionRepository sectionRepository;

public DataInitializer(LineRepository lineRepository, StationRepository stationRepository, SectionRepository sectionRepository) {
this.lineRepository = lineRepository;
this.stationRepository = stationRepository;
this.sectionRepository = sectionRepository;
}


public void initializeStations() {
List<String> stationData = List.of("교대역", "강남역", "역삼역", "남부터미널역", "양재역", "양재시민의숲역", "매봉역");
stationData.forEach(stationName -> stationRepository.addStation(new Station(stationName)));
}

public void initializeLines() {
Map<String, List<String>> lineData = Map.of(
"2호선", List.of("교대역", "강남역", "역삼역"),
"3호선", List.of("교대역", "남부터미널역", "양재역", "매봉역"),
"신분당선", List.of("강남역", "양재역", "양재시민의숲역")
);

lineData.forEach((lineName, stationNames) -> {
Line line = new Line(lineName);
Section section = new Section(line);
stationNames.forEach(stationName -> section.addStation(new Station(stationName)));
lineRepository.addLine(line);
sectionRepository.addSection(section);
});
}


}
1 change: 0 additions & 1 deletion src/main/java/subway/domain/Line.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ public String getName() {
return name;
}

// 추가 기능 구현
}
Loading