-
Notifications
You must be signed in to change notification settings - Fork 1.2k
๐ 5๋จ๊ณ - ์๋์ฐจ ๊ฒฝ์ฃผ(๋ฆฌํฉํ ๋ง) #6096
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
Lee-YuGyeong
wants to merge
10
commits into
next-step:lee-yugyeong
Choose a base branch
from
Lee-YuGyeong:step5
base: lee-yugyeong
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ba7ae98
refactor: ๋๋ค ๊ฐ ๊ตฌํ๋ ๋ถ๋ถ ๋ฆฌํฉํ ๋ง
Lee-YuGyeong d2802ff
refactor: ๊ฒ์ ์ปจ๋๋กค๋ฌ ์์ฑ
Lee-YuGyeong 600587f
test : ์๋์ฐจ ์์ฑ ํ
์คํธ ์ฝ๋ ์ถ๊ฐ
Lee-YuGyeong 0972640
refactor: ํจํค์ง ์ด๋
Lee-YuGyeong 6751a74
fix: ๋ฒ๊ทธ ์์
Lee-YuGyeong f2f1806
refactor: ์ฐ์น์ ์ฐพ๋ ๋ฉ์๋ ๋ฆฌํฉํ ๋ง
Lee-YuGyeong 8a91531
refactor: name์ ํด๋์ค๋ก ๋ถ๋ฆฌ
Lee-YuGyeong 3bb27ff
refactor: position ํด๋์ค ์์ฑ
Lee-YuGyeong 53ac8f8
chore: ์ถ๋ ฅ ์์
Lee-YuGyeong 140bc78
refactor: ๋ฏธ์ฌ์ฉ ํ์ผ ์ญ์
Lee-YuGyeong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,11 @@ | ||
import java.util.List; | ||
import controller.GameController; | ||
|
||
public class ApplicationMain { | ||
public static void main(String[] args) { | ||
|
||
List<String> carNames = InputView.getCarName(); | ||
int tryCount = InputView.getTryCount(); | ||
InputView.closeScanner(); | ||
|
||
Racing racing = new Racing(carNames, tryCount); | ||
|
||
racing.start(); | ||
GameController gameController = new GameController(); | ||
|
||
gameController.play(); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package controller; | ||
|
||
import domain.Racing; | ||
import java.util.List; | ||
import view.InputView; | ||
import view.ResultView; | ||
|
||
public class GameController { | ||
public void play() { | ||
List<String> carNames = InputView.getCarName(); | ||
int tryCount = InputView.getTryCount(); | ||
InputView.closeScanner(); | ||
|
||
Racing racing = new Racing(carNames); | ||
|
||
ResultView.printExecuteResult(); | ||
|
||
for (int i = 0; i < tryCount; i++) { | ||
racing.start(); | ||
ResultView.printRaceRound(racing); | ||
} | ||
|
||
ResultView.printWinner(racing); | ||
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package domain; | ||
|
||
|
||
public class Car { | ||
private final static int MOVE_BOUND = 4; | ||
private final static int MOVE_STEP = 1; | ||
|
||
private final CarName name; | ||
private final Position position; | ||
|
||
public Car(String name) { | ||
this.name = new CarName(name); | ||
this.position = new Position(0); | ||
} | ||
|
||
public Car(String name, int position) { | ||
this.name = new CarName(name); | ||
this.position = new Position(position); | ||
} | ||
|
||
/** | ||
* ์๋์ฐจ๋ฅผ ์์ผ๋ก ์ ์ง์ํต๋๋ค. | ||
*/ | ||
public void move(int randomNo) { | ||
if (randomNo >= MOVE_BOUND) { | ||
this.position.add(MOVE_STEP); | ||
} | ||
} | ||
|
||
public int maxComparedTo(int maxScore) { | ||
return this.position.maxComparedTo(maxScore); | ||
} | ||
|
||
public String getName() { | ||
return name.getName(); | ||
} | ||
|
||
public Boolean isSame(int input) { | ||
return this.position.isSame(input); | ||
} | ||
Comment on lines
+38
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. .compareTo() ์ค๋ฒ๋ผ์ด๋๋ก ๋ฐ๊ฟ์ฃผ์ธ์. |
||
|
||
public int getPosition() { | ||
return position.getPosition(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package domain; | ||
|
||
public class CarName { | ||
|
||
private static final int MAX_LENGTH = 5; | ||
private final String value; | ||
|
||
public CarName(String value) { | ||
if (value == null || value.trim().isEmpty()) { | ||
throw new IllegalArgumentException("์๋์ฐจ ์ด๋ฆ์ ๋น์ด ์์ ์ ์์ต๋๋ค"); | ||
} | ||
|
||
if (value.trim().length() > 5) { | ||
throw new IllegalArgumentException("์๋์ฐจ ์ด๋ฆ์ 5์๋ฅผ ์ด๊ณผํ ์ ์์ต๋๋ค"); | ||
} | ||
|
||
this.value = value; | ||
} | ||
|
||
public String getName() { | ||
return value; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package domain; | ||
|
||
public class Position { | ||
private int value; | ||
|
||
public Position(int value) { | ||
if (value < 0) { | ||
throw new IllegalArgumentException("์์น ๊ฐ์ ์์๊ฐ ์ฌ ์ ์์ต๋๋ค"); | ||
} | ||
this.value = value; | ||
} | ||
|
||
public void add(int moveStep) { | ||
this.value += moveStep; | ||
} | ||
|
||
public int maxComparedTo(int input) { | ||
return Math.max(this.value, input); | ||
} | ||
|
||
public Boolean isSame(int input) { | ||
return value == input; | ||
} | ||
|
||
public int getPosition() { | ||
return value; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import util.RandomUtil; | ||
|
||
public class Racing { | ||
private final List<Car> carList = new ArrayList<>(); // ์๋์ฐจ ๋ฆฌ์คํธ | ||
|
||
/** | ||
* @param carNames | ||
* ๋ ์ด์ฑ ์ด๊ธฐํ | ||
*/ | ||
public Racing(List<String> carNames) { | ||
for (String name : carNames) { | ||
carList.add(new Car(name)); | ||
} | ||
} | ||
|
||
/** | ||
* ๋ ์ด์ฑ ์์ | ||
*/ | ||
public void start() { | ||
for (Car car : carList) { | ||
int randomNo = RandomUtil.generate(); | ||
car.move(randomNo); | ||
} | ||
} | ||
|
||
public List<Car> getCarList() { | ||
return carList; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class Winners { | ||
|
||
/** | ||
* ์ฐ์น์๋ฅผ ์ฐพ์ต๋๋ค. | ||
* @param cars | ||
* @return | ||
*/ | ||
public static List<Car> findWinners(List<Car> cars) { | ||
|
||
int maxScore = 0; | ||
for (Car car : cars) { | ||
maxScore = car.maxComparedTo(maxScore); | ||
} | ||
|
||
int finalMaxScore = maxScore; | ||
|
||
return cars.stream() | ||
.filter(car -> car.isSame(finalMaxScore)) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package util; | ||
|
||
import java.util.Random; | ||
|
||
public class RandomUtil { | ||
private static final int BOUND = 10; | ||
|
||
public static int generate() { | ||
return new Random().nextInt(BOUND); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/main/java/InputView.java โ src/main/java/view/InputView.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
package view; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
import java.util.List; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package view; | ||
|
||
import domain.Car; | ||
import domain.Racing; | ||
import domain.Winners; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class ResultView { | ||
|
||
public static void printRaceRound(Racing racing) { | ||
for (Car car : racing.getCarList()) { | ||
System.out.println(car.getName() + " : " + "-".repeat(car.getPosition())); | ||
} | ||
System.out.println("\n"); | ||
} | ||
|
||
public static void printExecuteResult() { | ||
System.out.println("์คํ ๊ฒฐ๊ณผ"); | ||
} | ||
|
||
public static void printWinner(Racing racing) { | ||
List<Car> winners = Winners.findWinners(racing.getCarList()); | ||
|
||
String winnerNames = winners.stream() | ||
.map(Car::getName) | ||
.collect(Collectors.joining(", ")); | ||
|
||
System.out.println(winnerNames + "๊ฐ ์ต์ข ์ฐ์นํ์ต๋๋ค."); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ด๊ฒ์ Comparable ๋ก ํ์ด๋ณผ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค.