Skip to content
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
50533b8
Initial 해야할 일 작성
impactrudia Jul 5, 2019
c2427fc
Add 프로젝트 구조 생성
impactrudia Jul 5, 2019
3eabb9e
Test 플레이어_이름이_5글자_넘는_경우
impactrudia Jul 5, 2019
acd2e92
Test 라인겹치는 경우와 안 겹치는 경우
impactrudia Jul 5, 2019
5a1f9c9
Test 사다리 한줄 생성
impactrudia Jul 5, 2019
b0eef9b
Test 문자열을_쉽표로_구분할때_사람_명수
impactrudia Jul 5, 2019
62c9f54
사다리 인원 출력
impactrudia Jul 5, 2019
ed1f7b4
Add 사다리 출력
impactrudia Jul 5, 2019
0b54be4
Refactor StringUtils함수사용, 공백제거
impactrudia Aug 2, 2019
a920066
Add 입력하는것 결과 텍스트
impactrudia Aug 2, 2019
6092c51
Update 당첨결과
impactrudia Aug 3, 2019
b3e6bc1
step2 중간 구현
Aug 3, 2019
47776fc
# add : 결과확인 기능 구현중
willing1026 Aug 3, 2019
113231c
Update 라인진행중
impactrudia Aug 3, 2019
e80745c
step2 결과 구하기
Aug 3, 2019
2ffd68d
# add : 결과확인 기능 구현중
willing1026 Aug 3, 2019
3e3740e
Update 일단 완성 리팩토링 필요
impactrudia Aug 3, 2019
2d1c563
Update 리팩토링 구조 변경
impactrudia Aug 10, 2019
928efca
Update results List<String>형태로 변환
impactrudia Aug 10, 2019
4cec062
Create LadderGameMapper
impactrudia Aug 10, 2019
560ebfb
Modify : 결과Mapper 구현중
willing1026 Aug 10, 2019
ee14b60
중간구현
Aug 10, 2019
7bda094
Update 실행결과 all
impactrudia Aug 10, 2019
7c044ee
Modify : 결과공백문제 해결
willing1026 Aug 10, 2019
a459186
결과값 반복 구현
Aug 10, 2019
301eb83
Udpate pushtest
impactrudia Sep 28, 2019
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
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,20 @@
* 모든 피드백을 완료하면 다음 단계를 도전하고 앞의 과정을 반복한다.

## 온라인 코드 리뷰 과정
* [텍스트와 이미지로 살펴보는 온라인 코드 리뷰 과정](https://github.com/nextstep-step/nextstep-docs/tree/master/codereview)
* [텍스트와 이미지로 살펴보는 온라인 코드 리뷰 과정](https://github.com/nextstep-step/nextstep-docs/tree/master/codereview)

## 클래스 구조 및 테스트 케이스 작성
* Persons
* 문자열을 잘 나눴는지
* 꽝, 당첨 내역 확인
* Person
* 플레이어 이름이 5글자 넘을때 예외처리
* Line
* 라인이 겹치는 경우
* 라인이 안겹치는 경우
* Ladder
* 사다리 한줄 생성
* InputView
* ResultView
* ConsoleMain
* 최종결과 확인해서 라인별로 반복한 값을 리턴시킴
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ repositories {
dependencies {
testCompile('org.junit.jupiter:junit-jupiter:5.4.2')
testCompile('org.assertj:assertj-core:3.11.1')
testCompile('junit:junit:4.12')
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
}
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Fri Jul 05 20:59:43 KST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip
31 changes: 31 additions & 0 deletions src/main/java/nextstep/main/ConsoleMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package nextstep.main;

import nextstep.main.view.InputView;
import nextstep.main.view.ResultView;
import nextstep.main.vo.Ladder;
import nextstep.main.vo.Persons;

public class ConsoleMain {
public static void main(String []args){
String playersName = InputView.playerNames();
String playerResults = InputView.ladderResultPreDiction();

int ladderHeight = InputView.maxLadderHeight();

Persons persons = Persons.generate(playersName);
Persons results = Persons.generate(playerResults);

Ladder ladder = new Ladder();
ladder.generateLadder(ladderHeight, persons.getPersonCount());

ResultView.executeNames(persons);
ResultView.drawLadder(ladder);
ResultView.executeResults(results);


persons.settingResult(ladder, results);
String personName = InputView.personResult();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

all 이 아닌경우에는 반복해서 결과볼 수 있게 바꿔보면 좋을거 같아ㅎㅎ
요구사항에 반복하라는 얘기는 없어보이는데 all일때만 종료되는것 처럼 예시가 나와있어서
all일때만 종료되도록 바꿔보는것도 좋을거 같아!

결과를 보고 싶은 사람은?
pobi

실행 결과
꽝

결과를 보고 싶은 사람은?
all

ResultView.textResultPerson(persons.getLadderResult(personName));

}
}
29 changes: 29 additions & 0 deletions src/main/java/nextstep/main/view/InputView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package nextstep.main.view;

import java.util.Scanner;

public class InputView {
public static String playerNames() {
System.out.println("참여할 사람 이름을 입력하세요. (이름은 쉼표(,)로 구분하세요)");
Scanner scanner = new Scanner(System.in);
return scanner.nextLine();
}

public static String ladderResultPreDiction(){
System.out.println("실행 결과를 입력하세요. (결과는 쉼표(,)로 구분하세요)");
Scanner scanner = new Scanner(System.in);
return scanner.nextLine();
}

public static int maxLadderHeight() {
System.out.println("최대 사다리 높이는 몇 개인가요?");
Scanner scanner = new Scanner(System.in);
return scanner.nextInt();
}

public static String personResult(){
System.out.println("결과를 보고 싶은 사람은?\n");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

여기 앞쪽에 라인피드\n 추가하면 좋을거 같아!
실행하면 사다리 결과랑 붙어서 나오고 있어

꽝 500 100 200 결과를 보고 싶은 사람은?

Scanner scanner = new Scanner(System.in);
return scanner.nextLine();
}
}
36 changes: 36 additions & 0 deletions src/main/java/nextstep/main/view/ResultView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package nextstep.main.view;

import nextstep.main.vo.Ladder;
import nextstep.main.vo.Persons;

public class ResultView {
public static void executeNames(Persons persons){
System.out.println("사다리 결과");

persons.getPersons()
.forEach(System.out::print);


System.out.println();
}

public static void drawLadder(Ladder ladder) {
ladder.getLines()
.forEach(System.out::println);
}

public static void executeResults(Persons results){
results.getPersons()
.forEach(System.out::print);
}

public static void textResultPerson(String result){
System.out.println("실행 결과");
System.out.println(result);
}

public static void textResultAll(){
System.out.println("실행 결과");

}
}
35 changes: 35 additions & 0 deletions src/main/java/nextstep/main/vo/Ladder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package nextstep.main.vo;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;

public class Ladder {
private List<Line> lines;

public Ladder() {
this.lines = new ArrayList<>();
}

public int generateLadder(int ladderHeight, int playerCount) {
IntStream.range(0, ladderHeight)
.mapToObj(item -> new Line(playerCount))
.forEach(line -> this.lines.add(line));

return this.lines.size();
}

public List<Line> getLines() {
return this.lines;
}

public int getResult(int position) {
int currentPosition = position;

for(int i = 0; i< lines.size(); i++) {
currentPosition = lines.get(i).getPlusMinusPosition(currentPosition);
}

return currentPosition;
}
}
96 changes: 96 additions & 0 deletions src/main/java/nextstep/main/vo/Line.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package nextstep.main.vo;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.IntStream;

public class Line {
private static final int START_POINT = 0;
public static final String VERTICAL = "|";
public static final int HORIZONTAL_SIZE = 5;
public static final String DASH = "-";
public static final String EMPTY = " ";

private List<Boolean> points;
Comment thread
impactrudia marked this conversation as resolved.

Line(int countOfPerson) {
generateLine(countOfPerson);
}

private int generateLine(int countOfPerson) {
points = new ArrayList<>();

IntStream.range(0, numberOfPoints(countOfPerson))
.forEach(i -> points.add(generateCurrentPoint(i)));

return points.size();
}

private static int numberOfPoints(int countOfPerson) {
return countOfPerson - 1;
}

private boolean generateCurrentPoint(int newPosition) {
boolean point = new Random().nextBoolean();

if (isOverLapped(newPosition, point)) {
point = !point;
}

return point;
}

private boolean isOverLapped(int currPosition, boolean newPoint) {
if (currPosition == START_POINT)
return false;

return isEqual(points.get(currPosition - 1), newPoint);
}

static boolean isEqual(boolean prevPoint, boolean newPoint) {
return prevPoint == newPoint;
}

@Override
public String toString() {
final StringBuilder str = new StringBuilder(" |");
points.forEach(b -> str.append(pointToString(b)));

return str.toString();
}

private String pointToString(boolean b) {
if (b) {
return StringUtils.leftPad(VERTICAL, HORIZONTAL_SIZE, DASH);
}
return StringUtils.leftPad(VERTICAL, HORIZONTAL_SIZE, EMPTY);
}

public List<Boolean> getPoints() {
return points;
}

public int getPlusMinusPosition(int currentPosition) {
if (currentPosition == 0) {
return points.get(0) ? currentPosition + 1 : currentPosition;
}

if (currentPosition == points.size()) {
return points.get(currentPosition - 1) ? currentPosition - 1 : currentPosition;
}

if (points.get(currentPosition)) {
return currentPosition + 1;
}


if(points.get(currentPosition-1)) {
return currentPosition -1;
}

return currentPosition;
}
}
36 changes: 36 additions & 0 deletions src/main/java/nextstep/main/vo/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package nextstep.main.vo;

import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Person {
private static final int MAX_NAME_COUNT = 5;

private String name;
private String result;

public Person(String name) {
if (name.length() > MAX_NAME_COUNT)
throw new IllegalArgumentException();

this.name = name;
}

public Person(String name, String result) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

사용되는곳이 없대!

this.name = name;
this.result = result;
}

@Override
public String toString() {
String str = IntStream.range(0, MAX_NAME_COUNT - this.name.length())
.mapToObj(i -> " ")
.collect(Collectors.joining("", this.name, " "));

return str;
}

public boolean isMatch(String personName) {
return name.equals(personName);
}
}
77 changes: 77 additions & 0 deletions src/main/java/nextstep/main/vo/Persons.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package nextstep.main.vo;

import nextstep.main.view.ResultView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class Persons {
private static final String NAME_SEPARATOR = ",";

private List<Person> persons;
private List<Person> results;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

이거 어떻게 할지 고민해보면 좋을거 같아ㅠㅠ
Person객체랑 똑같아질거긴 한데, 이걸 어떻게 하면 좋을거 같긴 한데...


public Persons(List<Person> players) {
this.persons = Collections.unmodifiableList(players);
this.results = new ArrayList<>();
}

public static Persons generate(String names) {
List<Person> persons = Arrays.stream(split(names))
.map(Person::new)
.collect(Collectors.toList());
return new Persons(persons);
}

private static String[] split(String value) {
return value.split(NAME_SEPARATOR);
}

public int getPersonCount() {
return this.persons.size();
}

public List<Person> getPersons() {
return this.persons;
}

public int getStartPosition(String personName) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

사용되는곳이 없는거 같아

int index = 0;
for (Person person : persons) {
if (person.isMatch(personName)) {
return index;
}
index++;
}
throw new IllegalArgumentException("잘못된 참여자 이름입니다.");
}

public void settingResult(Ladder ladder, Persons results) {
for (int i = 0 ; i < persons.size() ; i++ ) {
int resultPosition = ladder.getResult(i);
this.results.add(results.getPersons().get(resultPosition));
}
}

public String getLadderResult(String personName) {
if(personName.equals("all")){
StringBuilder sb = new StringBuilder();
for(int i = 0 ; i< persons.size() ; i++){
sb.append(persons.get(i).toString() + " : " + results.get(i).toString());
sb.append("\n");
}
return sb.toString();
}
int resultIdx = 0;
for(int i = 0 ; i< persons.size() ; i++){
if(personName.equals(persons.get(i))){
resultIdx = i;
break;
}
}
return results.get(resultIdx).toString();
}
}
7 changes: 7 additions & 0 deletions src/test/java/nextstep/main/ConsoleMainTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package nextstep.main;

import static org.junit.Assert.*;

public class ConsoleMainTest {

}
Loading