Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5daad96
docs(README): docs/README.md 에 기능 구현 목록 작성
xrabcde Dec 13, 2020
693dbbb
feat(Application, Line, LineRepository): 프로그램 시작 시 사전등록된 정보로 초기 설정하는 …
xrabcde Dec 15, 2020
faf2096
fix(LineRepository): 초기설정 시에 index range 에러 수정
xrabcde Dec 15, 2020
2dc3160
feat(Application): 메인화면 기능 목록과 입력 안내문구 출력 및 메인기능 입력 구현
xrabcde Dec 15, 2020
9407e6f
feat(Application): 메인 기능 입력 예외처리를 위해 displayErrorMessage 메소드 구현 및 예외처리
xrabcde Dec 15, 2020
3b2f345
feat(Application): 선택한 메뉴에 따른 각 서브 메뉴 목록 출력 구현
xrabcde Dec 15, 2020
cc25b23
feat(Line): 노선별 노선도 출력을 위해 Line 클래스에 displayLine 메소드 구현
xrabcde Dec 15, 2020
1571548
feat(Application): 메인메뉴 4번의 노선도출력을 해주는 showPrintLines() 메소드 구현
xrabcde Dec 15, 2020
62cd4fe
feat(Application): 역관리와 노선관리 - 기능 입력 및 예외처리 구현
xrabcde Dec 15, 2020
aa8ea53
refactor: 메인메뉴와 서브메뉴의 입력, 예외처리를 한 메소드에서 하도록 리팩토링 (중복제거)
xrabcde Dec 15, 2020
7de82bf
feat(StationRepository): 중복된 역이 있는지 검사하는 isExist 메소드 구현
xrabcde Dec 15, 2020
f097254
docs(README.md): README 에러처리 방법 수정
xrabcde Dec 15, 2020
2ab9e9d
refactor: 메인화면으로 돌아가는 로직 위해 startProgram으로 리팩토링
xrabcde Dec 15, 2020
4bbc434
feat(Application): 역관리와 노선관리를 선택한 경우의 하위항목 로직 구현
xrabcde Dec 15, 2020
6d592ac
feat(Application): 역 등록을 위해 이름 입력 및 예외처리 addStation 구현
xrabcde Dec 15, 2020
d7aedb2
feat(Line): 해당 역이 노선에 등록되어있는지 확인해주는 hasStation 구현
xrabcde Dec 15, 2020
0897ffa
feat(Application): 역삭제 기능 구현
xrabcde Dec 15, 2020
b1cd488
docs(README.md): README 에러처리 수정
xrabcde Dec 15, 2020
0eb23c1
feat(Application): 역조회, 노선조회 구현
xrabcde Dec 15, 2020
77420f4
fix(Application): 노선도 출력 후 다시 메인 화면으로 돌아가도록 수정
xrabcde Dec 15, 2020
97dfff9
feat(LineRepository): 중복된 노선이 있는지 검사하는 isExist 메소드 구현
xrabcde Dec 15, 2020
66d6697
feat(Application): 노선등록 기능 구현
xrabcde Dec 15, 2020
60cd822
fix(Application): 등록하려는 노선의 상행과 하행이 같으면 등록되지 않도록 에러처리 추가
xrabcde Dec 15, 2020
1d78f6c
feat(Application): 노선 삭제 기능 구현
xrabcde Dec 15, 2020
9cc2242
feat(LineRepository): 구간추가를 위해 노선이름으로 노선으르 가져오는 getLineByName과 노선에 역을…
xrabcde Dec 15, 2020
aed417a
feat(Line): 구간등록 시 등록할 위치의 에러처리를 위해 노선의 길이를 받아오는 getSize 구현
xrabcde Dec 15, 2020
debb42e
feat(Application): 구간 등록 기능 구현
xrabcde Dec 15, 2020
57335f5
docs(README.md): README에 예외사항 추가
xrabcde Dec 15, 2020
01dae78
feat(Line): 구간삭제를 위해 Line 클래스에 특정 역을 삭제하는 deleteStation 구현
xrabcde Dec 15, 2020
2c1bd6d
feat(LineRepository): 노선이름과 역이름으로 특정 구간을 삭제하는 deleteStationInLine 구현
xrabcde Dec 15, 2020
89c4268
feat(Application): 구간 삭제 기능 구현
xrabcde Dec 15, 2020
9f28808
refactor: 상수 자료형들 Constants로 리팩토링
xrabcde Dec 15, 2020
ce0e4c7
refactor: 에러메시지 출력 메소드 리팩토링
xrabcde Dec 15, 2020
b4c6fc1
refactor: View 클래스 추가 및 리팩토링
xrabcde Dec 15, 2020
a9628c6
refactor: Errors 클래스 추가 및 예외처리 메소드 리팩토링
xrabcde Dec 15, 2020
d984f3c
refactor: Init 클래스 추가 및 코드 리팩토링
xrabcde Dec 15, 2020
2e7511b
refactor: InputView 클래스 추가 및 코드 리팩토링
xrabcde Dec 15, 2020
2f93163
refactor: SectionManage 클래스 추가 및 리팩토링
xrabcde Dec 15, 2020
729d037
refactor: StationManage 리팩토링
xrabcde Dec 15, 2020
1378fc9
refactor: LineManage 리팩토링
xrabcde Dec 15, 2020
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
103 changes: 103 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# 미션 - 지하철 노선도 미션 🚇

### 💻 기능 구현 목록

- 프로그램 시작 시, 사전 등록정보로 역과 노선 초기 설정
- 메인화면 기능 목록(1, 2, 3, 4, Q)과 입력 안내 문구 출력
- 원하는 기능 입력
- `예외` (1, 2, 3, 4, Q) 외에 다른 값을 입력한 경우
- `처리` 에러 문구([ERROR]) 출력 후 다시 입력

#### 1 역관리
- 역 관리 화면 기능 목록(1, 2, 3, B)과 입력 안내 문구 출력
- 원하는 기능 입력
- `예외` (1, 2, 3, B) 외에 다른 값을 입력한 경우
- `처리` 에러 문구([ERROR]) 출력 후 메인화면으로 돌아감
- `1 역등록`
- 역 이름 입력 받는 문구 출력
- 등록할 역 이름 입력
- `예외` 이미 등록된 역인 경우
- `예외` 역 이름이 2글자 미만인 경우
- `처리` 에러 문구([ERROR]) 출력 후 메인화면으로 돌아감
- 등록완료 문구 출력 후 메인화면으로 돌아감
- `2 역삭제`
- 역 이름 입력 받는 문구 출력
- 삭제할 역 이름 입력
- `예외` 등록되지 않은 역인 경우
- `예외` 노선에 등록된 역인 경우 => 역삭제 불가
- `처리` 에러 문구([ERROR]) 출력 후 메인화면으로 돌아감
- 삭제완료 문구 출력 후 메인화면으로 돌아감
- `3 역조회`
- 역 목록 출력 후 메인 화면으로 돌아감
- `B 돌아가기`
- 메인화면으로 돌아감

#### 2 노선관리
- 노선 관리 화면 기능 목록(1, 2, 3, B)과 입력 안내 문구 출력
- 원하는 기능 입력
- `예외` (1, 2, 3, B) 외에 다른 값을 입력한 경우
- `처리` 에러 문구([ERROR]) 출력 후 메인화면으로 돌아감
- `1 노선등록`
- 노선 입력 받는 문구 출력
- 등록할 노선 이름 입력
- `예외` 이미 등록된 노선일 경우
- `예외` 노선 이름이 2글자 미만인 경우
- `처리` 에러 문구([ERROR]) 출력 후 메인화면으로 돌아감
- 등록할 노선의 상행 종점역 입력안내 문구 출력 및 입력
- `예외` 등록되지 않은 역일 경우
- `처리` 에러 문구([ERROR]) 출력 후 메인화면으로 돌아감
- 등록할 노선의 하행 종점역 입력안내 문구 출력 및 입력
- `예외` 등록되지 않은 역일 경우
- `처리` 에러 문구([ERROR]) 출력 후 메인화면으로 돌아감
- `예외` 상행종점역과 같은 역을 입력한 경우
- `처리` 에러 문구([ERROR]) 출력 후 메인화면으로 돌아감
- 등록완료 문구 출력 후 메인화면으로 돌아감
- `2 노선삭제`
- 노선 입력 받는 문구 출력
- 삭제할 노선 이름 입력
- `예외` 등록되지 않은 노선일 경우
- `처리` 에러 문구([ERROR]) 출력 후 메인화면으로 돌아감
- 삭제완료 문구 출력 후 메인화면으로 돌아감
- `3 노선조회`
- 노선 목록 출력 후 메인화면으로 돌아감
- `B 돌아가기`
- 메인화면으로 돌아감

#### 3 구간관리
- 구간 관리 화면 기능 목록(1, 2, B)과 입력 안내 문구 출력
- 원하는 기능 입력
- `예외` (1, 2, B) 외에 다른 값을 입력한 경우
- `처리` 에러 문구(`[ERROR]`) 출력 후 다시 입력
- `1 구간등록`
- 노선 입력 받는 문구 출력
- 구간등록할 노선 입력
- `예외` 등록되지 않은 노선일 경우
- `처리` 에러 문구([ERROR]) 출력 후 메인화면으로 돌아감
- 역이름 입력 받는 문구 출력
- 등록할 역이름 입력
- `예외` 이미 해당 노선에 존재하는 역일 경우
- `예외` 등록되지 않은 역일 경우
- `처리` 에러 문구([ERROR]) 출력 후 메인화면으로 돌아감
- 등록할 순서 입력 (순서는 1부터 시작)
- `예외` 숫자가 아닌 값을 입력한 경우
- `예외` Range밖의 Index값을 입력한 경우
- `처리` 에러 문구([ERROR]) 출력 후 메인화면으로 돌아감
- 구간등록 완료 문구 출력 후 메인화면으로 돌아감
- `2 구간삭제`
- 노선 입력 받는 문구 출력
- 구간삭제할 노선 입력
- `예외` 등록되지 않은 노선일 경우
- `예외` 해당 노선에 포함된 역이 2개 이하일 경우 => 구간삭제 불가
- `처리` 에러 문구([ERROR]) 출력 후 메인화면으로 돌아감
- 삭제할 역이름 입력
- `예외` 해당 노선에 등록되지 않은 역일 경우
- `처리` 에러 문구([ERROR]) 출력 후 메인화면으로 돌아감
- 구간삭제 완료 문구 출력 후 메인화면으로 돌아감
- `B 돌아가기` 메인화면으로 돌아감

#### 4 노선도출력
- 지하철 노선도 출력 후 메인화면으로 돌아감
- `[INFO]` (호선, ---, 역) 순으로 저장된 모든 노선출력

#### Q 종료
- 프로그램 종료
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Tue Dec 15 20:43:57 KST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
31 changes: 29 additions & 2 deletions src/main/java/subway/Application.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
package subway;

import subway.domain.*;

import java.util.Scanner;

public class Application {
public static void main(String[] args) {
final Scanner scanner = new Scanner(System.in);
// TODO: 프로그램 구현
Init.initialize();
startProgram(scanner);
}

public static void startProgram(Scanner kbd) {
View.showMainMenu();
String mainInput = InputView.inputFunction(kbd, Constants.MAIN_FUNCTIONS);
goSubMenu(mainInput, kbd);
}

public static void goSubMenu(String input, Scanner kbd) {
System.out.println();
if (input.equals(Constants.STATION_MENU))
StationManage.manageStation(kbd);
if (input.equals(Constants.LINE_MENU))
LineManage.manageLine(kbd);
if (input.equals(Constants.SECTION_MENU))
SectionManage.manageSection(kbd);
if (input.equals(Constants.PRINT_LINES))
View.displayAllLines(kbd);
if (input.equalsIgnoreCase(Constants.FINISH_PROGRAM))
finishProgram();
}

public static void finishProgram() {
System.out.println("## 프로그램 종료");
}
}
}
30 changes: 30 additions & 0 deletions src/main/java/subway/domain/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package subway.domain;

import java.util.Arrays;
import java.util.List;

public class Constants {
public static final int FUNCTION_INPUT_ERROR = 0;
public static final int ALREADY_EXIST_ERROR = 1;
public static final int NAME_LENGTH_ERROR = 2;
public static final int NO_SUCH_NAME_ERROR = 3;
public static final int HAS_IN_LINE_ERROR = 4;
public static final int SAME_NAME_ERROR = 5;
public static final int HAS_IN_SPECIFIC_LINE_ERROR = 6;
public static final int UNVALID_INDEX_ERROR = 7;
public static final int CANT_DELETE_SECTION_ERROR = 8;
public static final int HAS_NOT_IN_SPECIFIC_LINE_ERROR = 9;

public static final List<String> MAIN_FUNCTIONS = Arrays.asList("1", "2", "3", "4", "Q");
public static final String STATION_MENU = "1";
public static final String LINE_MENU = "2";
public static final String SECTION_MENU = "3";
public static final String PRINT_LINES = "4";
public static final String FINISH_PROGRAM = "Q";
public static final List<String> SUB_FUNCTIONS = Arrays.asList("1", "2", "3", "B");
public static final String ADD_MENU = "1";
public static final String DELETE_MENU = "2";
public static final String SEARCH_MENU = "3";
public static final String GO_BACK_MENU = "B";
public static final List<String> SECTION_FUNCTIONS = Arrays.asList("1", "2", "B");
}
26 changes: 26 additions & 0 deletions src/main/java/subway/domain/ErrorMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package subway.domain;

public class ErrorMessage {
public static void displayErrorMessage(int errorCase) {
if (errorCase == Constants.FUNCTION_INPUT_ERROR)
System.out.println("[ERROR] 선택할 수 없는 기능입니다.");
if (errorCase == Constants.ALREADY_EXIST_ERROR)
System.out.println("[ERROR] 이미 등록된 역/노선 이름입니다.");
if (errorCase == Constants.NAME_LENGTH_ERROR)
System.out.println("[ERROR] 이름을 2글자 이상 입력해주세요.");
if (errorCase == Constants.NO_SUCH_NAME_ERROR)
System.out.println("[ERROR] 등록되지 않은 역/노선 이름입니다.");
if (errorCase == Constants.HAS_IN_LINE_ERROR)
System.out.println("[ERROR] 노선에 등록된 역은 삭제할 수 없습니다.");
if (errorCase == Constants.SAME_NAME_ERROR)
System.out.println("[ERROR] 상행역과 하행역은 같을 수 없습니다.");
if (errorCase == Constants.HAS_IN_SPECIFIC_LINE_ERROR)
System.out.println("[ERROR] 이미 해당 노선에 존재하는 역입니다.");
if (errorCase == Constants.UNVALID_INDEX_ERROR)
System.out.println("[ERROR] Range 내의 정수만 입력할 수 있습니다.");
if (errorCase == Constants.CANT_DELETE_SECTION_ERROR)
System.out.println("[ERROR] 역이 2개 이하인 노선의 구간은 삭제할 수 없습니다.");
if (errorCase == Constants.HAS_NOT_IN_SPECIFIC_LINE_ERROR)
System.out.println("[ERROR] 해당 노선에 존재하지 않는 역입니다.");
}
}
101 changes: 101 additions & 0 deletions src/main/java/subway/domain/Errors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package subway.domain;

import java.util.List;

public class Errors {
public static boolean checkInput(String input, List<String> functions) {
boolean check = true;
if (!functions.contains(input)) {
ErrorMessage.displayErrorMessage(Constants.FUNCTION_INPUT_ERROR);
check = false;
}
return check;
}

public static void checkSameStation(String name) {
if (StationRepository.isExist(name)) {
ErrorMessage.displayErrorMessage(Constants.ALREADY_EXIST_ERROR);
throw new IllegalArgumentException();
}
}

public static void checkSameLine(String name) {
if (LineRepository.isExist(name)) {
ErrorMessage.displayErrorMessage(Constants.ALREADY_EXIST_ERROR);
throw new IllegalArgumentException();
}
}

public static void checkSameName(String firstName, String lastName) {
if (firstName.equals(lastName)) {
ErrorMessage.displayErrorMessage(Constants.SAME_NAME_ERROR);
throw new IllegalArgumentException();
}
}

public static void checkTextLength(String name) {
if (name.length() < 2) {
ErrorMessage.displayErrorMessage(Constants.NAME_LENGTH_ERROR);
throw new IllegalArgumentException();
}
}

public static void checkExistStation(String name) {
if (!StationRepository.isExist(name)) {
ErrorMessage.displayErrorMessage(Constants.NO_SUCH_NAME_ERROR);
throw new IllegalArgumentException();
}
}

public static void checkExistLine(String name) {
if (!LineRepository.isExist(name)) {
ErrorMessage.displayErrorMessage(Constants.NO_SUCH_NAME_ERROR);
throw new IllegalArgumentException();
}
}

public static void checkInLine(String name) {
for (Line line : LineRepository.lines())
if (line.hasStation(name)) {
ErrorMessage.displayErrorMessage(Constants.HAS_IN_LINE_ERROR);
throw new IllegalArgumentException();
}
}

public static Line checkInSpecificLine(String lineName, String stationName) {
Line line = LineRepository.getLineByName(lineName);
if (line.hasStation(stationName)) {
ErrorMessage.displayErrorMessage(Constants.HAS_IN_SPECIFIC_LINE_ERROR);
throw new IllegalArgumentException();
}
return line;
}

public static void checkNotInSpecificLine(String lineName, String stationName) {
Line line = LineRepository.getLineByName(lineName);
if (!line.hasStation(stationName)) {
ErrorMessage.displayErrorMessage(Constants.HAS_NOT_IN_SPECIFIC_LINE_ERROR);
throw new IllegalArgumentException();
}
}

public static void checkValidIndex(Line line, String index) {
try {
int intIndex = Integer.parseInt(index);
int size = line.getSize();
if (intIndex < 1 || intIndex > size+1)
throw new IndexOutOfBoundsException();
} catch (Exception e) {
ErrorMessage.displayErrorMessage(Constants.UNVALID_INDEX_ERROR);
throw new IllegalArgumentException();
}
}

public static void checkValidLine(String name) {
Line line = LineRepository.getLineByName(name);
if (line.getSize() < 3) {
ErrorMessage.displayErrorMessage(Constants.CANT_DELETE_SECTION_ERROR);
throw new IllegalArgumentException();
}
}
}
26 changes: 26 additions & 0 deletions src/main/java/subway/domain/Init.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package subway.domain;

import java.util.Arrays;
import java.util.List;

public class Init {
public static void initialize() {
initializeStation();
initializeLine();
}

public static void initializeStation() {
List<String> names = Arrays.asList("교대역", "강남역", "역삼역", "남부터미널역", "양재역", "양재시민의숲역", "매봉역");
for (String name : names)
StationRepository.addStation(new Station(name));
}

public static void initializeLine() {
Line line2 = new Line("2호선");
LineRepository.addLine(line2, Arrays.asList("교대역", "강남역", "역삼역"));
Line line3 = new Line("3호선");
LineRepository.addLine(line3, Arrays.asList("교대역", "남부터미널역", "양재역", "매봉역"));
Line lineSinbundang = new Line("신분당선");
LineRepository.addLine(lineSinbundang, Arrays.asList("강남역", "양재역", "양재시민의숲역"));
}
}
17 changes: 17 additions & 0 deletions src/main/java/subway/domain/InputView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package subway.domain;

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

public class InputView {
public static String inputFunction(Scanner kbd, List<String> functions) {
String input = "0";
boolean check = false;
while(!check) {
System.out.println("\n## 원하는 기능을 선택하세요.");
input = kbd.nextLine();
check = Errors.checkInput(input, functions);
}
return input;
}
}
Loading