Skip to content
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
36 changes: 36 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
### 기능 요구사항

[ ✅ ] 주어진 지하철 정보를 초기화한다.

[ ✅ ] 아래와 같이 입력을 받는다.
```
## 메인 화면
1. 경로 조회
Q. 종료

## 원하는 기능을 선택하세요.
1

## 경로 기준
1. 최단 거리
2. 최소 시간
B. 돌아가기

## 원하는 기능을 선택하세요.
1

## 출발역을 입력하세요.
교대역

## 도착역을 입력하세요.
양재역
```
- 입력 받을 때, 경로 조회 시 출발역과 도착역이 같으면 에러를 출력한다.
- 정상적으로 입력하지 않았다면, 에러를 출력한다.

[X] 경로 조회 시 출발역과 도착역이 연결되어 있지 않으면 에러를 출력한다.
- 모든 역이 서로 연결되어있기때문에 위 내용 구현X

[ ✅ ] 총 거리를 구한다.

[ ✅ ] 총 소요시간을 구한다.
22 changes: 21 additions & 1 deletion src/main/java/subway/Application.java

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 application에서는 controller만 받게끔 만들어 봐야 겠어요!!

Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
package subway;

import subway.controller.GraphController;
import subway.controller.LineController;
import subway.controller.StationController;
import subway.controller.SubwayController;
import subway.view.InputView;
import subway.view.OutputView;

import java.util.Scanner;

import static subway.repository.LineRepository.lines;
import static subway.repository.StationRepository.stations;

public class Application {

private static final LineController lineController = new LineController();
private static final StationController stationController = new StationController();
private static final SubwayController subwayController = new SubwayController();
private static final GraphController graphController = new GraphController();
public static void main(String[] args) {
lineController.initLine();
stationController.initStation();
subwayController.initSubway();
graphController.initGraph();
final Scanner scanner = new Scanner(System.in);
// TODO: 프로그램 구현
InputView.init(scanner);
subwayController.start();
}
}
16 changes: 16 additions & 0 deletions src/main/java/subway/controller/GraphController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package subway.controller;

import subway.service.GraphService;

public class GraphController {
private final GraphService graphService;

public GraphController(){
graphService = new GraphService();
}

public void initGraph(){
graphService.initGraph();
}

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

import subway.service.LineService;

public class LineController {

private final LineService lineService;
public LineController(){
lineService = new LineService();
}

public void initLine(){
lineService.initLine();
}
}
15 changes: 15 additions & 0 deletions src/main/java/subway/controller/StationController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package subway.controller;

import subway.service.StationService;

public class StationController {
private final StationService stationService;

public StationController(){
stationService = new StationService();
}

public void initStation(){
stationService.initStation();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

계층 구조를 잘 지키셨군요! 👍

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

import subway.service.GraphService;
import subway.service.SubwayService;
import subway.util.message.InputMessage;
import subway.util.message.Menu;
import subway.view.InputView;
import subway.view.OutputView;

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

public class SubwayController {
private final SubwayService subwayService;
private final GraphService graphService;
private final List<String> main = new ArrayList<>(List.of(Menu.SELECT_ROUTINE.getKey(), Menu.EXIT.getKey()));
private final List<String> routine = new ArrayList<>(List.of(Menu.SHORTEST_DISTANCE.getKey(), Menu.SHORTEST_TIME.getKey(), Menu.BACK.getKey()));

private int totalDistance;
private int totalTime;
private List<String> path;
public SubwayController(){
subwayService = new SubwayService();
graphService = new GraphService();
}

public void initSubway(){
subwayService.initSubway();
}

public void start(){
while(questionIsproceed()){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

낙타표기법에 의해 questionIsProceed() 라고 작명하면 좋겠군요!

try{
questionRoutine();
} catch(IllegalArgumentException e){
OutputView.printMessage(e.getMessage());
questionRoutine();
}
}
}

private boolean questionIsproceed(){
OutputView.printMain();
String input = InputView.inputKey(main);
return confirmProceed(input);
}

private boolean confirmProceed(final String input){
if(input.equals(Menu.EXIT.getKey())){
return false;
}
return input.equals(Menu.SELECT_ROUTINE.getKey());
}

private void questionRoutine(){
OutputView.printRoutine();
String input = InputView.inputKey(routine);
questionMainNext(input);
}

private void questionMainNext(final String input){
if(input.equals(Menu.BACK.getKey())){
questionRoutine();
}
List<Integer> totalInfo = new ArrayList<>();
if(input.equals(Menu.SHORTEST_DISTANCE.getKey())){
totalInfo = getShortestDistance();
}
if(input.equals(Menu.SHORTEST_TIME.getKey())){
totalInfo = getShortestTime();
}
savetotalInfo(totalInfo);
OutputView.printResult(path, totalDistance, totalTime);
}

private List<Integer> getShortestDistance(){
String startStationInfo = InputView.inputStation(InputMessage.GET_START_STATION.getValue());
String endStationInfo = InputView.inputStation(InputMessage.GET_END_STARTION.getValue());
path = graphService.getShortestDistancePath(startStationInfo, endStationInfo);
return graphService.getTotalShortestDistanceAndShortestTime(path);
}

private List<Integer> getShortestTime(){
String startStationInfo = InputView.inputStation(InputMessage.GET_START_STATION.getValue());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getShorestDistance() 메서드와 내용이 중복되군요. startStationInfo, endStationInfo를 만드는 부분을 메서드로 만들면 어떨까요?

String endStationInfo = InputView.inputStation(InputMessage.GET_END_STARTION.getValue());
path = graphService.getShortestTimePath(startStationInfo, endStationInfo);
return graphService.getTotalShortestDistanceAndShortestTime(path);
}

private void savetotalInfo(final List<Integer> totalInfo){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 낙타표기법으로 saveTotalInfo()가 좋을거 같아요!

totalDistance = totalInfo.get(0);
totalTime = totalInfo.get(1);
}
}
33 changes: 33 additions & 0 deletions src/main/java/subway/domain/ConnectStationNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package subway.domain;

public class ConnectStationNode {
private Station station;
private int distance;
private int time;

private ConnectStationNode(Station station, int distance, int time){
this.station = station;
this.distance = distance;
this.time = time;
}

public static ConnectStationNode create(Station station, int distance, int time){
return new ConnectStationNode(station, distance, time);
}

public Station getStation(){
return station;
}

public int getDistance(){
return distance;
}

public int getTime(){
return time;
}

public String toString(){
return "연결된 역 정보 = " + station.getName() + "," + getDistance() + "," + getTime();
}
}
8 changes: 8 additions & 0 deletions src/main/java/subway/domain/Graph.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package subway.domain;

import org.jgrapht.graph.DefaultWeightedEdge;
import org.jgrapht.graph.WeightedMultigraph;
import subway.util.constants.StationName;

public class Graph {
}
22 changes: 20 additions & 2 deletions src/main/java/subway/domain/Line.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
package subway.domain;

import java.util.ArrayList;
import java.util.List;

public class Line {
private String name;
private List<Station> stations = new ArrayList<>();

public Line(String name) {
private Line(String name) {
this.name = name;
}

public static Line create(String name){
return new Line(name);
}

public void addStationsInLine(final Station station){
stations.add(station);
}

public String getName() {
return name;
}

// 추가 기능 구현
public boolean isEqualName(String name){
return name.equals(this.name);
}

public String toString(){
return name;
}
}
26 changes: 0 additions & 26 deletions src/main/java/subway/domain/LineRepository.java

This file was deleted.

25 changes: 23 additions & 2 deletions src/main/java/subway/domain/Station.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
package subway.domain;

import java.util.*;

public class Station {
private String name;
private List<ConnectStationNode> connectStationNodes = new ArrayList<>();

public Station(String name) {
private Station(String name) {
this.name = name;
}

public static Station create(String name){
return new Station(name);
}

public void addConnectStations(final ConnectStationNode connectStationNode){
connectStationNodes.add(connectStationNode);
}

public String getName() {
return name;
}

// 추가 기능 구현
public boolean isEqualName(String name){
return name.equals(this.name);
}

public List<ConnectStationNode> getConnectStationNodes() {
return Collections.unmodifiableList(connectStationNodes);
}

public String toString(){
return name;
}
}
26 changes: 0 additions & 26 deletions src/main/java/subway/domain/StationRepository.java

This file was deleted.

Loading