Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
57232d7
feat: README.md 생성
msmn1729 Dec 15, 2020
63d9034
docs: 구현해야할 기능목록 작성
msmn1729 Dec 15, 2020
831e71e
Update README.md
msmn1729 Dec 15, 2020
d3d0250
feat: 처음 역을 세팅하는 기능구현
msmn1729 Dec 15, 2020
62046da
Update README.md
msmn1729 Dec 15, 2020
248cb57
Merge branch 'msmn1729' of https://github.com/msmn1729/java-subway-ma…
msmn1729 Dec 15, 2020
042c74e
feat: 노선을 관리할 수 있도록 메소드 추가
msmn1729 Dec 15, 2020
c52b440
feat: 처음 노선(2호선, 3호선, 신분당선), 구간 등록
msmn1729 Dec 15, 2020
d0a5739
Update README.md
msmn1729 Dec 15, 2020
32235d8
feat: 메인선택에서 입력에 대한 예외처리
msmn1729 Dec 15, 2020
8d92491
feat: 메인 클래스에서 실행하도록 구현
msmn1729 Dec 15, 2020
aa22824
feat: 지하철 노선도 출력하는 메소드 구현
msmn1729 Dec 15, 2020
0c9d4d7
fix: 오탈자 수정
msmn1729 Dec 15, 2020
2eb845e
feat: 역 등록기능 구현
msmn1729 Dec 15, 2020
9ba63fd
feat: 역 삭제, 역 목록 출력 기능 구현
msmn1729 Dec 15, 2020
159a1de
Update README.md
msmn1729 Dec 15, 2020
8a1fa15
feat: 등록되지 않은 역 이름일 경우 예외처리
msmn1729 Dec 15, 2020
c4ded15
Update README.md
msmn1729 Dec 15, 2020
0111082
Merge branch 'msmn1729' of https://github.com/msmn1729/java-subway-ma…
msmn1729 Dec 15, 2020
6568562
Update README.md
msmn1729 Dec 15, 2020
5e36024
feat: 노선 목록 출력 메소드 구현
msmn1729 Dec 15, 2020
2678cb5
refactor: 코드 정리
msmn1729 Dec 15, 2020
4c5260d
feat: 구간관리 입력 클래스 생성
msmn1729 Dec 15, 2020
7f835dd
Update README.md
msmn1729 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
517 changes: 517 additions & 0 deletions docs/README.md

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions src/main/java/Controller/LineController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package Controller;
import subway.domain.Line;
import subway.domain.LineRepository;
import subway.domain.Station;
import subway.domain.StationRepository;

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

public class LineController {

public static void runLineController(Scanner scanner) {
System.out.println("## 노선 관리 화면\n" +
"1. 노선 등록\n" +
"2. 노선 삭제\n" +
"3. 노선 조회\n" +
"B. 돌아가기\n" +
"\n" +
"## 원하는 기능을 선택하세요.");

String userInput = scanner.nextLine();
boolean inputCheck = false;
if (userInput.equals("1")) {
inputCheck = true;
addLine(scanner);
}
if (userInput.equals("2")) {
inputCheck = true;
}
if (userInput.equals("3")) {
showLine();
inputCheck = true;
}
if (userInput.equals("B")) {
inputCheck = true;
SubwayController.run(scanner);
}
if (inputCheck == false) {
System.out.println("[ERROR] 올바른 번호를 입력해주세요");
LineController.runLineController(scanner);
}
}
public static void addLine(Scanner scanner) {
System.out.println("지하철 노선이 등록되었습니다.");
}
static void showLine() {
System.out.println("## 노선 목록");
List<Line> lines = LineRepository.lines();
for (Line line : lines) {
System.out.println(line.getName());
}
}
}
32 changes: 32 additions & 0 deletions src/main/java/Controller/SectionController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package Controller;

import java.util.Scanner;

public class SectionController {
public static void runSectionController(Scanner scanner) {
System.out.println("## 구간 관리 화면\n" +
"1. 구간 등록\n" +
"2. 구간 삭제\n" +
"B. 돌아가기\n" +
"\n" +
"## 원하는 기능을 선택하세요.");

String userInput = scanner.nextLine();

boolean inputCheck = false;
if (userInput.equals("1")) {
inputCheck = true;
}
if (userInput.equals("2")) {
inputCheck = true;
}
if (userInput.equals("B")) {
inputCheck = true;
SubwayController.run(scanner);
}
if (inputCheck == false) {
System.out.println("[ERROR] 올바른 번호를 입력해주세요");
SectionController.runSectionController(scanner);
}
}
}
78 changes: 78 additions & 0 deletions src/main/java/Controller/StationController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package Controller;

import subway.domain.Station;
import subway.domain.StationRepository;

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

public class StationController {
public static void runStationController(Scanner scanner) {
System.out.println("## 역 관리 화면\n" +
"1. 역 등록\n" +
"2. 역 삭제\n" +
"3. 역 조회\n" +
"B. 돌아가기\n" +
"\n" +
"## 원하는 기능을 선택하세요.");

String userInput = scanner.nextLine();

boolean inputCheck = false;
if (userInput.equals("1")) {
inputCheck = true;
addStation(scanner);
}
if (userInput.equals("2")) {
inputCheck = true;
deleteStation(scanner);
}
if (userInput.equals("3")) {
inputCheck = true;
showStation();
}
if (userInput.equals("B")) {
inputCheck = true;
SubwayController.run(scanner);
}
if (inputCheck == false) {
System.out.println("[ERROR] 올바른 번호를 입력해주세요");
StationController.runStationController(scanner);
}
}

public static void addStation(Scanner scanner) {
System.out.println("## 등록할 역 이름을 입력하세요");
String name = scanner.nextLine();
Station station = new Station(name);
StationRepository.addStation(station);
System.out.println("[INFO] 지하철 역이 등록되었습니다.");
}

public static void deleteStation(Scanner scanner) {
System.out.println("## 삭제할 역 이름을 입력하세요");
String name = scanner.nextLine();
List<Station> stations = StationRepository.stations();
boolean flag = false;
for (Station station : stations) {
if(station.getName().equals(name)) flag = true;
}
if(flag) {
StationRepository.deleteStation(name);
System.out.println("[INFO] 지하철 역이 삭제되었습니다.");
}
if (!flag) {
System.out.println("[ERROR] 등록되자않은 역입니다.");
deleteStation(scanner);
}
}

public static void showStation() {
System.out.println("## 역 목록");
List<Station> stations = StationRepository.stations();
for (Station station : stations) {
System.out.println("[INFO] " + station.getName());
}
System.out.println();
}
}
75 changes: 75 additions & 0 deletions src/main/java/Controller/SubwayController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package Controller;

import subway.domain.Line;
import subway.domain.LineRepository;
import subway.domain.Station;

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

public class SubwayController {
private static String userInput;

public SubwayController(Scanner scanner) {
run(scanner);
}

public static void run(Scanner scanner) {
System.out.println("## 메인 화면\n" +
"1. 역 관리\n" +
"2. 노선 관리\n" +
"3. 구간 관리\n" +
"4. 지하철 노선도 출력\n" +
"Q. 종료\n" +
"\n" +
"## 원하는 기능을 선택하세요.");
userInput = scanner.nextLine();
mainSelect(scanner);
}

private static void mainSelect(Scanner scanner) {
boolean inputCheck = false;
if (userInput.equals("1")) {
inputCheck = true;
StationController.runStationController(scanner);
run(scanner);
}
if (userInput.equals("2")) {
inputCheck = true;
LineController.runLineController(scanner);
run(scanner);
}
if (userInput.equals("3")) {
inputCheck = true;
SectionController.runSectionController(scanner);
run(scanner);
}
if (userInput.equals("4")) {
inputCheck = true;
printSubway();
run(scanner);
}
if (userInput.equals("Q")) {
inputCheck = true;
scanner.close();
}
if (inputCheck == false) {
System.out.println("[ERROR] 올바른 번호를 입력해주세요");
run(scanner);
}
}

private static void printSubway() {
System.out.println("## 지하철 노선도");
List<Line> lines = LineRepository.lines();
for (Line line : lines) {
System.out.println("[INFO] " + line.getName());
System.out.println("[INFO] ---");
List<Station> stations = line.getSection();
for (Station station : stations) {
System.out.println("[INFO] " + station.getName());
}
System.out.println();
}
}
}
4 changes: 3 additions & 1 deletion src/main/java/subway/Application.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package subway;

import Controller.SubwayController;
import java.util.Scanner;

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

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

public class MakeSubway {
public void initSubway() {
Station gyodae = new Station("교대역");
Station gangnam = new Station("강남역");
Station yeoksam = new Station("역삼역");
Station nambuTerminal = new Station("남부터미널역");
Station yangjae = new Station("양재역");
Station yangjaeForest = new Station("양재시민의숲역");
Station maebong = new Station("매봉역");

StationRepository.addStation(gyodae);
StationRepository.addStation(gangnam);
StationRepository.addStation(yeoksam);
StationRepository.addStation(nambuTerminal);
StationRepository.addStation(yangjae);
StationRepository.addStation(yangjaeForest);
StationRepository.addStation(maebong);

Line secondLine = new Line("2호선", gyodae, yeoksam);
Line thirdLine = new Line("3호선", gyodae, maebong);
Line sinbundangLine = new Line("신분당선", gangnam, yangjaeForest);

LineRepository.addLine(secondLine);
LineRepository.addLine(thirdLine);
LineRepository.addLine(sinbundangLine);

secondLine.addSection(2, gangnam);
thirdLine.addSection(2, nambuTerminal);
thirdLine.addSection(3, yangjae);
sinbundangLine.addSection(2, yangjae);
}
}
24 changes: 22 additions & 2 deletions src/main/java/subway/domain/Line.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
package subway.domain;

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

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

public Line(String name) {
public Line(String name, Station upward, Station downward) {
this.name = name;
addSection(upward);
addSection(downward);
}

public String getName() {
return name;
}

// 추가 기능 구현
public void addSection(Station station) {
section.add(station);
}

public void addSection(int index, Station station) {
section.add(index, station);
}

public List<Station> getSection() {
return section;
}

public void deleteSection(int index) {
section.remove(index);
}
}
2 changes: 0 additions & 2 deletions src/main/java/subway/domain/Station.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ public Station(String name) {
public String getName() {
return name;
}

// 추가 기능 구현
}