Skip to content
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
fbfab99
Git -commit feat:1주차 과제(서현진)
Sep 11, 2025
1c54f83
Git -commit feat:1주차 과제(서현진)
Sep 11, 2025
dee665e
Git -commit feat: 하드코딩 수정
Sep 12, 2025
a9af148
Git -commit feat: RaceSetting 클래스 생성
Sep 12, 2025
c6d9acc
feat: Race,RaceSetting 클래스 생성
Sep 13, 2025
560ac39
feat: RaceWinner 클래스 생성
Sep 13, 2025
aeb4ab7
feat: setMoveCnt 메소드 생성
Sep 13, 2025
dcb4ec5
feat : 전체적인 코드 수정 및 구조 변경 ( Car, Race, RaceSetting, RaceWinner)
Sep 13, 2025
c11d098
feat : RaceSetting,RaceWinner 클래스 수정
Sep 13, 2025
480f751
feat : depth 2 이상 수정
Sep 13, 2025
c0d037a
feat : README 수정
Sep 13, 2025
62b3941
feat : README 수정2
Sep 13, 2025
864e6c0
feat : mvc 패턴 적용 - Car클래스 수정
Sep 15, 2025
97b4d95
feat : mvc 패턴 적용 - 새로운 클래스 'Cars'
Sep 15, 2025
035ecdd
feat : mvc 패턴 적용 - 새로운 클래스 'InputView'
Sep 15, 2025
0de29df
feat : mvc 패턴 적용 - 새로운 클래스 'OutputView'
Sep 15, 2025
f660a28
feat : mvc 패턴 적용 - 새로운 클래스 'RacingCController'
Sep 15, 2025
7f5f429
feat : mvc 패턴 적용 - 새로운 클래스 'Application'
Sep 15, 2025
630df3a
feat : EOF 관련 수정
Sep 15, 2025
22dc5a0
feat : 첫 커밋
Sep 16, 2025
704cf09
feat : 3,4단계 구현
Sep 18, 2025
c19c73a
feat : GenerateRandom의 반환 값을 boolean으로 변경 및 car클래스에서 random 메소드 제거
Sep 18, 2025
b608f5b
feat : GenerateRandom의 반환 값을 boolean으로 변경 및 car클래스에서 random 메소드 제거 2
Sep 18, 2025
b471111
feat : cars에 moveAll을 move로 변경
Sep 18, 2025
cd70b8a
feat : new function 'isValid' in InputView
Sep 18, 2025
66e64b6
Delete src/main/java/CarMain.java
nonactress Sep 18, 2025
68814e7
Delete src/main/java/Race.java
nonactress Sep 18, 2025
4f1b377
Delete src/main/java/RaceSetting.java
nonactress Sep 18, 2025
ced1092
Delete src/main/java/RaceWinner.java
nonactress Sep 18, 2025
fd0a317
feat : generate package
Sep 19, 2025
76330fc
깃 작동 여부 확인
Sep 19, 2025
03ef929
refactor(random): Improve name of random generation logic
Sep 19, 2025
3e12240
refactor(random): making 'RacingService'and refactoring 'RacingContro…
Sep 19, 2025
cd944bc
refactor(controller): making 'RacingService'and refactoring 'RacingCo…
Sep 19, 2025
5ca9b26
refactor(model): constructor 'car' delete
Sep 19, 2025
fb563ce
refactor(model): 'isFindingFirstPizes'changes to 'checkAndAddWinner'
Sep 19, 2025
482cf13
refactor(view): method 'PrintCarPostion' rogic
Sep 19, 2025
d5ef197
Merge branch 'hyeonjin-2' of https://github.com/nonactress/java-racin…
Sep 19, 2025
ad763d8
refactor(input): method 'getCarNames' rogic
Sep 19, 2025
cab4c5f
refactor(input): renaming about Random package
Sep 20, 2025
b160676
feat : RandomMoveStrategyTest
Sep 20, 2025
2831966
feat : isValid over 2 depth
Sep 20, 2025
ada34f1
feat (CarsWinner) : new class 'CarWinner'
Sep 22, 2025
eb25bf2
feat (Test) : delete 'Racing ControllerTest'
Sep 22, 2025
c2e519f
refactor (input) : change rogic 'getCarName'
Sep 22, 2025
43190b6
refactor (model,controller) : new class 'Carwinner'2
Sep 22, 2025
f6c6e25
refactor (view) :apply 'try-catch' rogic
Sep 22, 2025
3fb578e
refactor (view) : making Random rogic
Sep 24, 2025
7d22b1d
refactor (Number) : making Package 'Number'
Sep 24, 2025
72497ef
refactor (Number) : making 'FixedNumberGenerator'
Sep 24, 2025
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
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

---
## 작동 방식

애플리케이션은 다음 정보를 입력하라는 메시지를 표시합니다:

1. **자동차 수:** 경주에 참가할 자동차의 수
2. **라운드 수:** 경주가 지속될 라운드 수
3. **자동차 이름:** 각 자동차의 이름

필요한 정보를 입력하면 경주가 시작됩니다. 각 라운드마다 자동차는 전진할 기회를 갖습니다.
0부터 9 사이에서 무작위로 생성된 숫자가 4보다 크면 자동차는 전진합니다.
경주가 끝나면 각 자동차가 이동한 총 거리를 표시하고 우승자(들)를 발표합니다.

## 클래스 설명

* **`Car.java`**: 이름과 이동 횟수를 가진 자동차를 나타냅니다.
* **`RaceSetting.java`**: 경주를 설정하는 클래스입니다. 자동차 수, 라운드 수, 자동차 이름에 대한 사용자 입력을 받습니다. 또한 경주 실행과 자동차 이동에 관한 로직을 포함합니다.
* **`RaceWinner.java`**: 이 클래스는 `RaceSetting`을 확장하며 경주의 우승자를 결정하는 역할을 합니다. 가장 멀리 이동한 자동차를 찾아 그 이름을 우승자로 출력합니다.
* **`Race.java`**: 애플리케이션의 주요 진입점입니다. 경주를 시작하기 위해 `RaceWinner`의 인스턴스를 생성합니다.

---
7 changes: 7 additions & 0 deletions src/main/java/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public class Application {
public static void main(String[] args) {
RacingController racingController = new RacingController();
racingController.run();
}
}

25 changes: 25 additions & 0 deletions src/main/java/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
public class Car {

private String name;
private int position = 0;


public Car() {
}

Choose a reason for hiding this comment

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

안 쓰는 코드는 삭제해주세요!

Copy link
Author

Choose a reason for hiding this comment

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


public Car(String name) {
this.name = name;
}

public void move() {
this.position++;
}

public String getName() {
return name;
}

public int getPosition() {
return position;
}
}
63 changes: 63 additions & 0 deletions src/main/java/Cars.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Cars {
private final List<Car> cars;
GenerateRandom generateRandom = new GenerateCarRandom();
//GenerateRandom testGenerateRandom = new TestGenerateRandom(); //단위 테스트용 코드

public Cars(String[] carNames) {
this.cars = new ArrayList<>();
for (String name : carNames) {
cars.add(new Car(name));
}
}

public void moveAll() {
for (Car car : cars) {
move(car);
}
}

private void move(Car car) {
if (generateRandom.generate()) {
car.move();
}
// if (testGenerateRandom.generate()) {
// car.move();
// }
}

public List<String> findWinners() {
int maxPosition = findMaxPosition();
List<String> winners = new ArrayList<>();
for (Car car : cars) {
isFindingFirstPizes(winners, car, maxPosition);
}
return winners;
}

private void isFindingFirstPizes(List<String> winners, Car car, int maxPosition) {
Copy link

@SANGHEEJEONG SANGHEEJEONG Sep 18, 2025

Choose a reason for hiding this comment

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

is로 메서드명을 지으면 보통 boolean을 반환한다고 오해하기 쉬운데요, 어떤 동작을 하는지가 더 명확히 드러나는 이름은 어떨까요? 추가로 Pizes 오타난 것 같습니다!

Copy link
Author

Choose a reason for hiding this comment

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

isFindingFirstPrizes => checkAndAddWinner 로 수정했습니다!

if (car.getPosition() == maxPosition) {
winners.add(car.getName());
}
}

private int findMaxPosition() {
int maxPosition = 0;
for (Car car : cars) {
maxPosition = Math.max(car.getPosition(), maxPosition);
}
return maxPosition;
}

public List<Car> getCars() {
return Collections.unmodifiableList(cars);

/*return this.cars;
*위 방식을 안쓴 이유는 객체를 받아서 다른 메소드나 클래스에서
*수정이 가능해 지기 때문에 위 컬렉션 메소드로 반환값 설정
* */
}
}
14 changes: 14 additions & 0 deletions src/main/java/GenerateCarRandom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import java.util.Random;

public class GenerateCarRandom implements GenerateRandom {
private Random random = new Random();

@Override
public boolean generate() {
if (random.nextInt(10) > MOVE_CONDITION) {
return true;
}
return false;

}
}
4 changes: 4 additions & 0 deletions src/main/java/GenerateRandom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public interface GenerateRandom {
static final int MOVE_CONDITION = 4;
boolean generate();
}
33 changes: 33 additions & 0 deletions src/main/java/InputView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import java.util.Scanner;

public class InputView {
private static final Scanner scanner = new Scanner(System.in);

public static String[] getCarNames() {
System.out.println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)");
String[] splitCar = scanner.nextLine().split(",");
return splitCar;
}

public static int getRaceCount() {
System.out.println("시도할 회수는 몇회인가요?");
int count = scanner.nextInt();
scanner.nextLine(); // 개행 문자 제거
return count;
}

public static boolean isValid(String [] cars){
if(cars.length == 1 ){
System.out.println("한 개 이상의 자동차를 입력해주세요!");
return false;
}
for (String car : cars) {
if(car.trim().isEmpty())
{
System.out.println("자동차의 이름이 공백일 순 없습니다!");
return false;
}
}
return true;
}

Choose a reason for hiding this comment

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

현재 이 함수가 안 쓰이는 것으로 보이는데 맞나요?
✚ 추가로 depth가 깊어 보입니다!

Copy link
Author

Choose a reason for hiding this comment

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

아직 그 단위 테스트 할 때 써보려고 만든 함수인데 미완이라 수정해보겠습니다!

}
28 changes: 28 additions & 0 deletions src/main/java/OutputView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.util.List;

public class OutputView {

public static void printResultMessage() {
System.out.println("\n실행 결과");
}

public static void printRoundResult(List<Car> cars) {
for (Car car : cars) {
System.out.print(car.getName() + " : ");
printCarPosition(car);
System.out.println();
}
System.out.println();
}

private static void printCarPosition(Car car) {
for (int i = 0; i < car.getPosition(); i++) {

Choose a reason for hiding this comment

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

참고) 이런 방법도 있답니다!

private static void printCarPosition(Car car) {
    System.out.print("-".repeat(car.getPosition()));
}

Copy link
Author

Choose a reason for hiding this comment

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

훨씬 깔끔하네요! 수정하겠습니다!

System.out.print("-");
}
}

public static void printWinners(List<String> winners) {
String winnerNames = String.join(", ", winners);
System.out.println("최종 우승자 : " + winnerNames);
}
}
16 changes: 16 additions & 0 deletions src/main/java/RacingController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class RacingController {
public void run() {
String[] carNames = InputView.getCarNames();
int raceCount = InputView.getRaceCount();

Cars cars = new Cars(carNames);

OutputView.printResultMessage();
for (int i = 0; i < raceCount; i++) {
cars.moveAll(); // Model의 상태 변경 요청
OutputView.printRoundResult(cars.getCars()); // View에 출력 요청
}

OutputView.printWinners(cars.findWinners());
}
}

Choose a reason for hiding this comment

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

현진님은 컨트롤러가 어떤 역할을 한다고 생각하시나요?

현재 현진님의 컨트롤러는 크게 아래와 같은 역할을 모두 수행하는 것 같습니다!

  1. InputView로부터 자동차 이름과 시도 횟수를 받아옵니다.
  2. 입력받은 이름으로 Cars 객체를 생성합니다.
  3. OutputView의 각종 출력 메서드를 호출합니다.
  4. for 반복문을 통해 전체 레이싱 게임의 흐름을 직접 관리합니다.

저는 컨트롤러는 뷰를 통해 입력을 받은 후 모델에 전달하는 역할을 한다고 생각합니다. 현재는 제어의 역할을 넘어 전체 게임의 진행과 흐름을 모두 책임지고 있는데요, 게임 진행 책임은 컨트롤러에서 분리시키는 것이 어떨까요?

MVC 패턴에서 컨트롤러의 역할이 어디까지라고 생각하시는지 현진님의 생각을 들려주시면 감사하겠습니다!

Copy link
Author

Choose a reason for hiding this comment

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

저는 컨트롤러 안에서 말씀하신대로 controller안에서 게임이 흐름이 보여야 한다고 생각해서 위와 같은 방식으로 코드를 구성했습니다!
위의 피드백 수용해서 'RacingService'를 만들었습니다!

Choose a reason for hiding this comment

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

RacingService로 로직을 분리해주셨군요!

사실 제가 처음 리뷰를 드릴 때 의도했던 바를 조금 더 명확하게 설명드리고 싶어서 추가 의견을 남깁니다. 제가 착각해서 조금 헷갈리게 말을 작성했던 것 같아요. 죄송해요 🥲

제가 처음에 컨트롤러의 책임을 언급하며 혼동했던 이유는 게임의 전체적인 흐름과 상태를 관리하는 모델이 없다 보니, 컨트롤러가 직접 Cars를 제어하면서 게임 진행까지 책임지는 것처럼 보였기 때문인데요, 이전 코멘트의 원래 의도는 레이싱 게임의 상태와 행위를 함께 관리하는 새로운 모델 객체를 만드는 것이었습니다.

현재는 Cars가 자동차 목록을 관리하는 동시에 우승자를 찾는 역할(findWinners)까지 수행하고 있는데요, 여기서 한 걸음 더 나아가 Cars는 자동차들의 일급 컬렉션 역할에만 집중하게 하고, 새로 만든 게임 담당 객체가 Cars를 소유하며 게임 진행 자체를 책임지게 하는 구조는 어떨까요?

이렇게 구조를 바꾸면 좋은 점은...

  • 객체별 책임이 명확해집니다
    • Car: 자동차 하나의 상태를 책임집니다.
    • Cars: 자동차 '목록'을 관리하는 책임에만 집중합니다.
    • Racing: 게임의 규칙과 상태를 책임집니다.
  • 응집도가 높아집니다.
    • 게임과 관련된 로직이 RacingGame 하나에 모여있어 나중에 게임 규칙이 바뀌더라도 RacingGame 클래스만 수정하면 됩니다.
  • 컨트롤러는 정말 지휘만 하게 됩니다.
    • 컨트롤러는 game.startRound() 처럼 더 높은 수준의 명령만 내리면 됩니다.

지금 제안 드린 구조에 대해서는 어떻게 생각하시는지 편하게 의견 남겨주세요!

11 changes: 11 additions & 0 deletions src/main/java/TestGenerateRandom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class TestGenerateRandom implements GenerateRandom {
private final int TEST_NUM = 5;

@Override
public boolean generate() {
if (TEST_NUM > MOVE_CONDITION) {
return true;
}
return false;
}
}