Skip to content

Doyeon/week2 과제 제출#70

Open
dp44rk wants to merge 8 commits intomainfrom
doyeon/week2
Open

Doyeon/week2 과제 제출#70
dp44rk wants to merge 8 commits intomainfrom
doyeon/week2

Conversation

@dp44rk
Copy link

@dp44rk dp44rk commented Apr 7, 2025

Racing Car Game

주요 변경 사항

  • Java Naming Convention 준수
    • 클래스명, 변수명, 메서드명을 카멜/파스칼 케이스로 통일함.
  • First-Class Collection
    • Cars 클래스를 통해 List<Car> 직접 접근을 제한하고 책임을 위임.
  • Strategy Pattern
    • MovingStrategy 인터페이스와 RandomMovingStrategy 구현체를 통해 이동 조건을 유연하게 처리.
  • Validator 클래스 분리
    • 입력값 검증 책임을 Validator 클래스에서 전담.
  • 기본 생성자 추가

클래스 및 메소드

Application.java

  • 프로그램 실행의 진입점.
  • 사용자 입력을 받고 유효성을 검사하여 게임을 실행.

Car.java

  • 각 자동차 객체를 표현.
  • 주요 필드:
    • name: 자동차 이름 (final)
    • position: 현재 위치
  • 주요 메소드:
    • strategyMove(MovingStrategy strategy): 전략 객체에 따라 조건을 만족하면 이동.
    • getName(), getPosition(), setPosition(): 속성 접근용 getter/setter.
    • PrintInfo(): 이름과 현재 위치를 출력 (디버깅용)

Cars.java

  • 여러 Car 객체를 관리하는 일급 컬렉션.
  • 생성자:
    • Cars(List<Car> cars)
    • Cars(String[] carNames): 이름 배열로부터 자동차 리스트를 생성하며 유효성 검사를 수행.
  • 주요 메소드:
    • getCars(): 자동차 리스트 반환
    • printInfo(): 각 자동차의 위치를 -로 시각화하여 출력
    • getWinners(): 최종 우승자 리스트 반환 (최고 위치를 가진 자동차들)

MovingStrategy.java

  • 자동차 이동 여부를 판단하는 전략 인터페이스.
  • 메소드:
    • boolean canMove(): 이동 가능 여부 판단

RandomMovingStrategy.java

  • 무작위 수를 생성하여 이동 여부를 결정하는 전략 구현체.
  • 0~9 중 무작위 수가 4 이상이면 이동.

RacingGame.java

  • 경주 로직 실행 및 결과 출력 담당 클래스.
  • 주요 메소드:
    • playGame(Cars cars, int count, MovingStrategy strategy): 정해진 횟수만큼 자동차들을 전략에 따라 이동시키고 매 턴 상태 출력
    • printWinners(Cars cars): 최고 위치의 자동차 이름들을 출력

Validator.java

  • 입력값 유효성 검사를 담당하는 static 유틸 클래스.
  • 주요 메소드:
    • tryCountValidator(String tryCountInput): 시도 횟수의 유효성을 검사하고 정수로 반환
    • carNameValidator(String name): 자동차 이름 유효성 검사 (빈값, 길이, 금지 문자 검사)

@dp44rk dp44rk linked an issue Apr 7, 2025 that may be closed by this pull request
Copy link

@glucosei glucosei left a comment

Choose a reason for hiding this comment

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

다 나름의 규칙으로 책임을 가지고 있는 것 같아서 좋은 객체지향프로그램인 것 같습니다. 수고하셨어요!

Copy link

Choose a reason for hiding this comment

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

개인적인 의견으로는 Car이나 Cars의 프린트하는 부분이나 비지니스로직 실행하는 부분이 다른 부분에서 값을 받아서 처리하는게 확장성이 더 좋을 것 같다는 생각이 있어요!

@ces0135-hub
Copy link

자동차 이름 입력에 대한 예외처리를 따로 구현해 놓은 것이 굉장히 인상적이었습니다.
그리고 최댓값을 찾을 때 저는 Math.max()를 사용할 생각을 못 했는데, 하나 배워갑니다.
수고하셨습니다!

Copy link
Member

Choose a reason for hiding this comment

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

상수로 사용하는거 좋은 것 같습니다

Copy link
Member

Choose a reason for hiding this comment

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

join 사용은 생각 못했네요

Copy link
Member

Choose a reason for hiding this comment

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

어차피 strip(',') 하면서 공백으로 저장되서 isEmptry에서 걸러지니까 불필요할 것 같습니다

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[2주차] : 레이싱카 리팩토링 과제 제출 - 박도연

4 participants