8000 [지하철 노선도 미션] 이주혁 미션 제출합니다. by JuHyuk-Lee · Pull Request #107 · woowacourse/java-subway-map-precourse · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[지하철 노선도 미션] 이주혁 미션 제출합니다. #107

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

Open
wants to merge 60 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
794f927
docs: 구현할 기능 목록 추가
JuHyuk-Lee Dec 14, 2020
86724c9
feat: 메인 메뉴 출력 기능 구현
JuHyuk-Lee Dec 14, 2020
b3b5404
feat: 원하는 메인 메뉴 입력 받는 기능 구현
JuHyuk-Lee Dec 14, 2020
9113a80
docs: 구현할 기능 목록 수정
JuHyuk-Lee Dec 14, 2020
1d49f1e
fix: 메인메뉴 종료 값 수정
JuHyuk-Lee Dec 14, 2020
04e850b
refactor: 클래스 이름 변경
JuHyuk-Lee Dec 14, 2020
93829a4
refactor: 변경된 클래스 삭제
JuHyuk-Lee Dec 14, 2020
f3ebe73
refactor: SubwayMap와 Menu의 중간역할 Manager 객체들 추가
JuHyuk-Lee Dec 14, 2020
151d5ac
style: 메소드 순서 변경
JuHyuk-Lee Dec 14, 2020
3829085
feat: 지하철 역 메뉴 출력 기능 구현
JuHyuk-Lee Dec 14, 2020
c50dfc3
docs: 구현할 기능 목록 추가
JuHyuk-Lee Dec 14, 2020
ba0855f
feat: 지하철 역 메뉴 입력 받는 기능 추가
JuHyuk-Lee Dec 14, 2020
ad5f929
refactor: 패키지 구조 변경
JuHyuk-Lee Dec 14, 2020
9277228
refactor: Input 메소드 구현 변경
JuHyuk-Lee Dec 14, 2020
6a4e39f
refactor: 기본 생성자 추가
JuHyuk-Lee Dec 14, 2020
99bc9e1
refactor: Scanner를 Input만 가지도록 변경
JuHyuk-Lee Dec 14, 2020
3f11a92
refactor: scanner 1번만 초기화 되도록 수정
JuHyuk-Lee Dec 14, 2020
236ddef
refactor: 뒤로가기 입력전까지 반복되도록 수정
JuHyuk-Lee Dec 14, 2020
fa95dc0
feat: 지하철 역 저장 기능 추가
JuHyuk-Lee Dec 14, 2020
ace323a
docs: 구현할 기능 목록 수정
JuHyuk-Lee Dec 14, 2020
91d4057
feat: 지하철역 등록 시 검증로직 추가
JuHyuk-Lee Dec 14, 2020
d490619
fix: 오타 수정
JuHyuk-Lee Dec 14, 2020
10fef5f
feat: 지하철 역 삭제 기능 구현
JuHyuk-Lee Dec 14, 2020
38e493e
feat: 지하철 역 조회 기능 추가
JuHyuk-Lee Dec 14, 2020
49b76cb
style: 불필요한 import문 제거
JuHyuk-Lee Dec 14, 2020
463f213
docs: 구현할 기능 목록 수정
JuHyuk-Lee Dec 14, 2020
b72b111
feat: 지하철 역 초기값 등록 기능 구현
JuHyuk-Lee Dec 14, 2020
781498a
docs: 구현할 기능 목록 수정
JuHyuk-Lee Dec 14, 2020
1cb4998
docs: 구현할 기능 목록 수정
JuHyuk-Lee Dec 14, 2020
82492dc
feat: Exception 추가
JuHyuk-Lee Dec 14, 2020
3069799
feat: 노선 메뉴 출력 기능 구현
JuHyuk-Lee Dec 14, 2020
13606c1
feat: 노선 메뉴 선택 기능 구현
JuHyuk-Lee Dec 14, 2020
6c15613
fix: 함수 호출 변경
JuHyuk-Lee Dec 15, 2020
c16d223
feat: 구현할 기능 목록 수정
JuHyuk-Lee Dec 15, 2020
a088003
refactor: 공백 출력 담당 변경
JuHyuk-Lee Dec 15, 2020
8db8064
refactor: 함수 기능 분리
JuHyuk-Lee Dec 15, 2020
95931df
feat: equals & hashCode 오버라이드
JuHyuk-Lee Dec 15, 2020
b57ff82
refactor: 불필요한 공백 라인 출력 제거
JuHyuk-Lee Dec 15, 2020
f0c5037
feat: 노선 등록 기능 구현
JuHyuk-Lee Dec 15, 2020
3bcac4a
docs: 구현할 기능 목록 수정
JuHyuk-Lee Dec 15, 2020
9ae1243
feat: 노선 삭제 기능 구현
JuHyuk-Lee Dec 15, 2020
eea2d1c
refactor: 공백 라인 출력 담당 함수 변경
JuHyuk-Lee Dec 15, 2020
18f09d7
refactor: 목록 출력 수정
JuHyuk-Lee Dec 15, 2020
686542e
refactor: manager 목록 출력 로직 변경
JuHyuk-Lee Dec 15, 2020
5924bed
refactor: 변수명, 함수명 변경
JuHyuk-Lee Dec 15, 2020
cabf2c4
feat: 노선 조회 기능 추가
JuHyuk-Lee Dec 15, 2020
a790fc1
fix: 한번 뒤로 간 메뉴 다시 사용 시 반복 안되는 버그 수정
JuHyuk-Lee Dec 15, 2020
76a9753
fix: 구간 관리 호출 메소드 변경
JuHyuk-Lee Dec 15, 2020
ed1aff9
refactor: 인터페이스 제거
JuHyuk-Lee Dec 15, 2020
c71d1a4
feat: 메뉴 상태 초기화 기능 추가
JuHyuk-Lee Dec 15, 2020
2bea165
refactor: 기본 생성자 추가
JuHyuk-Lee Dec 15, 2020
a49496f
style: 코딩 컨벤션 통일
JuHyuk-Lee Dec 15, 2020
03b6a55
feat: 에러 타입 추가
JuHyuk-Lee Dec 15, 2020
3b8ed7c
feat: 구간 출력 기능 구현
JuHyuk-Lee Dec 15, 2020
ce1a43d
docs: 구현할 기능 목록 수정
JuHyuk-Lee Dec 15, 2020
a064a56
feat: 구간 메뉴 선택 기능 구현
JuHyuk-Lee Dec 15, 2020
b3057e3
refactor: 출력 메세지 상수명 변경
JuHyuk-Lee Dec 15, 2020
3162b3b
feat: 지하철역 초기 설정 기능 구현
JuHyuk-Lee Dec 15, 2020
485571d
docs: 구현할 기능 목록 수정
JuHyuk-Lee Dec 15, 2020
07fac93
style: 자바 코딩 컨벤션
JuHyuk-Lee 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
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,62 @@
# 지하철 노선도 미션
- 지하철 역과 노선을 관리하는 지하철 노선도 기능을 구현한다.

## 구현할 기능 목록
* 데이터 초기 값 설정 기능
* 지하철 역 초기값 설정 기능
* 노선 초기값 설정 기능
* 메인 메뉴를 출력한다.
* 원하는 메인 메뉴를 입력 받는다.
* 선택할 수 없는 메뉴인지 검증한다.
* 지하철 역 메뉴를 출력한다.
* 지하철 역 메뉴를 입력 받는다.
* 선택할 수 없는 메뉴인지 검증한다.
* 지하철 역을 등록한다.
* 지하철 역 이름이 중복 되는지 검증한다.
* 지하철 역 이름이 2글자 이상인지 검증한다.
* 지하철 역을 삭제한다.
* 등록된 지하철 역인지 확인한다.
* 지하철 역 목록을 출력한다.
* 노선 메뉴를 출력한다.
* 원하는 노션 메뉴를 입력 받는다.
* 선택할 수 없는 메뉴인지 검증한다.
* 지하철 노선을 등록한다.
* 노선 이름이 중복 되는지 검증한다.
* 노선 이름이 2글자 이상인지 검증한다.
* 노선 종점역을 초기화 한다.
* 노선 상행 종점역을 등록한다.
* 노선 하행 종점역을 등록한다.
* 하행과 상행 종점에 등록된 역이 있는지 검증한다.
* 노선 하행과 상행 종점이 같은지 검증한다.
* 노선의 목록을 출력한다.
* 노선에 역을 추가한다.
* 같은 노선에 중복 된 역이 등록 되는지 검증한다.
* 노선의 상행 종점역 보다 앞에 역 등록을 하는지 검증한다.
* 노선의 하행 종점역 보다 뒤에 역 등록을 하는지 검증한다.
* 노선을 제거한다.
* 등록 된 노선인지 확인한다.
* 노선에 등록 된 역을 제거한다.
* 노선에서 제거 된 역이 종점인지 검증한다.
* 구간 메뉴를 출력한다.
* 원하는 메인 메뉴를 입력 받는다.
* 선택할 수 없는 메뉴인지 검증한다.

## 미구현 기능 목록
* 구간을 등록한다.
* 노선에 등록 된 지하철 역 보다 큰 숫자인지 검증
* 음수 입력 검증
* 구간을 삭제한다.
* 노선에 포함 된 역이 2개 이하인지 검증한다.
* 노선에 등록 된 역의 범위를 확인한다.
* 노선에 등록된 지하철인지 검증한다. ( 노선에 등록 된 역은 삭제 불가)
* 종점이 제거 될 경우 마지막 노선이 종점이 된다.
* 노선의 상행 종점부터 하행 종점까지 연결된 순서대로 역 목록을 출력한다.

<br>

## 🚀 기능 요구사항
<details>
<summary>더보기</summary>

### 초기 설정
- 프로그램 시작 시 역, 노선 등 필요한 정보를 미리 셋팅할 수 있다.
Expand Down Expand Up @@ -397,6 +450,7 @@ B. 돌아가기
### 프로그래밍 요구사항 - Application
- Application 클래스를 활용해 구현해야 한다.
- Application의 패키지 구조는 변경하지 않는다.
- 주석을 참고하여 구현할 수 있으며 주석대로 구현하지 않아도 되고 삭제해도 무관하다.
```java
public class Application {
public static void main(String[] args) {
Expand Down Expand Up @@ -453,6 +507,8 @@ public class StationRepository {
}
```

</details>

<br>

## 📈 진행 요구사항
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/subway/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ public class Application {
public static void main(String[] args) {
final Scanner scanner = new Scanner(System.in);
// TODO: 프로그램 구현
SubwayMap subway = new SubwayMap();
subway.run(scanner);
}
}
36 changes: 36 additions & 0 deletions src/main/java/subway/SubwayMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package subway;

import subway.domain.Line;
import subway.domain.LineRepository;
import subway.domain.Station;
import subway.domain.StationRepository;
import subway.manager.MainManager;
import subway.utils.InitLine;
import subway.utils.InitStation;
import subway.view.Input;
import java.util.Arrays;
import java.util.Scanner;

public class SubwayMap {

public void run(Scanner scanner) {
init(scanner);
MainManager.run();
}

private void init(Scanner scanner) {
Input.init(scanner);
initStations();
initLines();
}

private void initStations() {
Arrays.stream(InitStation.values())
.forEach(station -> StationRepository.addStation(new Station(station.name())));
}

private void initLines() {
Arrays.stream(InitLine.values())
.forEach(line -> LineRepository.addLine(new Line(line.getName())));
}
}
43 changes: 43 additions & 0 deletions src/main/java/subway/controller/LineController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package subway.controller;

import subway.domain.Line;
import subway.service.LineService;
import subway.view.Input;
import subway.view.Output;

public class LineController {

private LineController() {
}

public void save() {
try {
LineService.save(new Line(Input.input(Input.PLEASE_INPUT_LINE_NAME)));
} catch (IllegalArgumentException e) {
Output.printNewLine();
System.out.println(e.getMessage());
}
}

public void remove() {
try {
LineService.remove(Input.input(Input.PLEASE_INPUT_REMOVE_LINE_NAME));
} catch (IllegalArgumentException e) {
Output.printNewLine();
System.out.println(e.getMessage());
}
}

public void getList() {
Output.print(Output.LINE_LIST);
Output.printByList(LineService.getAllLines());
}

public static LineController getInstance() {
return LineController.LazyHolder.INSTANCE;
}

private static class LazyHolder {
private static final LineController INSTANCE = new LineController();
}
}
21 changes: 21 additions & 0 deletions src/main/java/subway/controller/SectionController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package subway.controller;

public class SectionController {

private SectionController () {
}

public void save() {
}

public void remove() {
}

public static SectionController getInstance() {
return SectionController.LazyHolder.INSTANCE;
}

private static class LazyHolder {
private static final SectionController INSTANCE = new SectionController();
}
}
44 changes: 44 additions & 0 deletions src/main/java/subway/controller/StationController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package subway.controller;

import subway.domain.Station;
import subway.service.StationService;
import subway.view.Input;
import subway.view.Output;

public class StationController {

private StationController() {
}

public void save() {
try {
StationService.save(new Station(Input.input(Input.PLEASE_INPUT_STATION_NAME)));
} catch (IllegalArgumentException e) {
Output.printNewLine();
System.out.println(e.getMessage());
}
}

public void remove() {
try {
Output.printNewLine();
StationService.remove(Input.input(Input.PLEASE_INPUT_REMOVE_STATION_NAME));
} catch (IllegalArgumentException e) {
Output.printNewLine();
System.out.println(e.getMessage());
}
}

public void getList() {
Output.print(Output.STATION_LIST);
Output.printByList(StationService.getAllStations());
}

public static StationController getInstance() {
return LazyHolder.INSTANCE;
}

private static class LazyHolder {
private static final StationController INSTANCE = new StationController();
}
}
25 changes: 25 additions & 0 deletions src/main/java/subway/domain/Line.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package subway.domain;

import subway.exception.TerminalNamesOverlapException;
import subway.service.StationService;
import subway.view.Input;

public class Line {
private String name;
private Station upwardTerminalStation;
private Station downTerminalStation;

public Line(String name) {
this.name = name;
Expand All @@ -12,4 +18,23 @@ public String getName() {
}

// 추가 기능 구현
public void initTerminalStations() {
Station upwardTerminalStation = StationService.isExists(
Input.input(Input.PLEASE_INPUT_UPWARD_TERMINAL_STATION_NAME));

Station downTerminalStation = StationService.isExists(
Input.input(Input.PLEASE_INPUT_DOWN_TERMINAL_STATION_NAME));

if (upwardTerminalStation.equals(downTerminalStation)) {
throw new TerminalNamesOverlapException();
}

this.upwardTerminalStation = upwardTerminalStation;
this.downTerminalStation = downTerminalStation;
}

@Override
public String toString() {
return name;
}
}
7 changes: 7 additions & 0 deletions src/main/java/subway/domain/LineRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

public class LineRepository {
private static final List<Line> lines = new ArrayList<>();
Expand All @@ -19,4 +20,10 @@ public static void addLine(Line line) {
public static boolean deleteLineByName(String name) {
return lines.removeIf(line -> Objects.equals(line.getName(), name));
}

public static Optional<Line> findByName(String name) {
return lines().stream()
.filter(line -> line.getName().equals(name))
.findFirst();
}
}
20 changes: 20 additions & 0 deletions src/main/java/subway/domain/Station.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,24 @@ public String getName() {
}

// 추가 기능 구현

@Override
public String toString() {
return name;
}

@Override
4D1F public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Station station = (Station) o;

return name != null ? name.equals(station.name) : station.name == null;
}

@Override
public int hashCode() {
return name != null ? name.hashCode() : 0;
}
}
7 changes: 7 additions & 0 deletions src/main/java/subway/domain/StationRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

public class StationRepository {
private static final List<Station> stations = new ArrayList<>();
Expand All @@ -19,4 +20,10 @@ public static void addStation(Station station) {
public static boolean deleteStation(String name) {
return stations.removeIf(station -> Objects.equals(station.getName(), name));
}

public static Optional<Station> findByName(String name) {
return stations().stream()
.filter(station -> station.getName().equals(name))
.findFirst();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package subway.exception;

public class LineNameDuplicateException extends IllegalArgumentException {
private static final String message = "[ERROR] 이미 등록된 노선 이름입니다.";

public LineNameDuplicateException() {
super(message);
}
}
9 changes: 9 additions & 0 deletions src/main/java/subway/exception/LineNameNotFoundException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package subway.exception;

public class LineNameNotFoundException extends IllegalArgumentException {
private static final String message = "[ERROR] 등록 되어 있지 않은 노선입니다.";

public LineNameNotFoundException() {
super(message);
}
}
9 changes: 9 additions & 0 deletions src/main/java/subway/exception/NameLengthException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package subway.exception;

public class NameLengthException extends IllegalArgumentException {
private static final String message = "[ERROR] 이름은 2글자 이상입니다.";

public NameLengthException() {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package subway.exception;

public class StationNameDuplicateException extends IllegalArgumentException{
private static final String message = "[ERROR] 이미 등록된 역 이름입니다.";

public StationNameDuplicateException() {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package subway.exception;

public class StationNameNotFoundException extends IllegalArgumentException {
private static final String message = "[ERROR] 등록 되어 있지 않은 역입니다.";

public StationNameNotFoundException() {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package subway.exception;

public class TerminalNamesOverlapException extends IllegalArgumentException {
private static final String message = "[ERROR] 하행 종점과 상행 종점이 같은 역입니다.";

public TerminalNamesOverlapException() {
super(message);
}
}
Loading
0