Skip to content

[자동차 경주] 장민서 미션 제출합니다. - #1447

Open
mingdodev wants to merge 12 commits into
woowacourse-precourse:mainfrom
mingdodev:mingdodev
Open

[자동차 경주] 장민서 미션 제출합니다.#1447
mingdodev wants to merge 12 commits into
woowacourse-precourse:mainfrom
mingdodev:mingdodev

Conversation

@mingdodev

Copy link
Copy Markdown

No description provided.

- Add list of features to implement.
- Add functional requirements.
- Implement method that returns boolean by random.
- If value of Random.pickNumberInRange is greater than 4,
the method returns true.
- Otherwise, it returns false.
- Use library to generate random number.
- Implement Car class to manage name, moveCount within single object.
- Define a constructor to set default value 0 for moveCount.
- Method move() updates moveCount using MoveDecision.byRandom().
- Implement some getter and setter.
- Split user input string to get each car's name.
- Create Car object and set name.
- Set tryInput to save how many games going to be done.
- Throw an IllegalArgumentException when invalid input occurs.
- Use enum to manage error messages.
Then separate methods.
Print game progress(try).
Update checklist.
@mingdodev

Copy link
Copy Markdown
Author

공부할 것

  • 패키지 분리는 언제 하는 것인가?
  • 패키지, 클래스, 메서드 이름 짓기
  • 예외 처리의 위치와 체크 예외 vs 언체크 예외
  • Set<String> hs = new HashSet<>();이 주는 효용에 대해 확실히 이해하고 사용하기
  • compareTo() 뜯어보기

@ajroot5685 ajroot5685 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2주차도 고생하셨어요~~~~🤗

import java.util.ArrayList;
import java.util.HashSet;

public class InputException {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

InputException이라는 클래스명에서 입력 오류를 처리할 것이라는 기대를 하게 되는데, 입력을 받는 것까지 처리해서 혼동이 올 수 있어보여요
분리하면 좋을 것 같습니다!

@mingdodev mingdodev Nov 4, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

어쩐지 클래스 이름을 지을 때 어떻게 지을지 고민하게 되더라고요 분리해달라고 클래스에서 보내는 신호였구나....!!
이름을 어떻게 바꿀지만 고민했는데 기능 분리가 더 올바른 방법이었네요!!

Comment on lines +26 to +31
HashSet<String> carNameSet = new HashSet<>();
for (String s : carInput) {
if (!carNameSet.add(s)) {
throw new IllegalArgumentException(ErrorMessage.DUPLICATE_NAME.toString());
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

저는 중복검사를 매번 데이터가 들어갈 때마다 Stream API의 anyMatch로 검사했는데요!
HashSet이 시간복잡도는 더 낫지만 중복검사용 데이터를 따로 저장해야 한다는 측면에서 두 방식의 장단점이 있는것 같습니다!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Stream API를 사용하는 방법이 있었네요!
HashSet을 따로 만드는 것이 좀 부자연스럽게 느껴졌는데, 다음에는 anyMatch를 사용해봐야겠어요!


private static void printProgress(ArrayList<Car> carList) {
for (Car c : carList) {
System.out.println(c.getName() + " : " + "-".repeat(c.getMoveCount()));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

repeat으로 깔끔하게 결과를 출력하셨네요 좋아요🚀

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

가독성을 높일 수 있는 방법을 계속 고민해봐야겠어요 🥳

매번 꼼꼼히 리뷰해주셔서 감사해요~~~!!

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 participants