Skip to content

이민우_BackEnd_1주차_과제제출#14

Open
Inforest10 wants to merge 1 commit intoBCSDLab-Edu:mainfrom
Inforest10:main
Open

이민우_BackEnd_1주차_과제제출#14
Inforest10 wants to merge 1 commit intoBCSDLab-Edu:mainfrom
Inforest10:main

Conversation

@Inforest10
Copy link
Copy Markdown

No description provided.

@Inforest10 Inforest10 changed the title 완성 이민우_BackEnd_1주차_과제제출 Mar 30, 2026
Car[] car = new Car[carCount];
for (int i = 0; i < carCount; i++) {
car[i] = new Car();
car[i].name = cars[i];
Copy link
Copy Markdown

@JanooGwan JanooGwan Mar 31, 2026

Choose a reason for hiding this comment

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

객체의 정보(필드)에 접근할 때에는 직접 접근하지 않고, Getter(접근자), Setter(수정자) 메소드를 클래스 안에 별도로 만들어서 접근하는 것이 일반적인 원칙입니다!
이는 보고서에서 작성해주신 정보은닉과 관련이 있습니다

public class Car {
  String name;
  
  public getName() { // 접근자
    return name;
  }

  public setName(String name) { // 수정자
    this.name = name;
  }
}

String name;
int count = 0;
public void move() {
if (Randoms.pickNumberInRange(0, 9) >= 4) {
Copy link
Copy Markdown

@JanooGwan JanooGwan Mar 31, 2026

Choose a reason for hiding this comment

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

4 와 같이 무언가 의미가 있는 숫자들은 상수로 처리하는 것을 권장합니다!

private static final int CAR_MOVE_STANDARD = 4;

public void move() {
  if(Randoms.pickNumberInRange(0, 9) >= CAR_MOVE_STANDARD) { ... }
}

throw new IllegalArgumentException("시도 횟수는 숫자여야 합니다.");
}

if (count <= 0) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

자바 메소드(Integer.signum())를 이용해서 양수/음수 를 판별할 수도 있습니다!

}

for (int k = 0; k < carCount; k++) {
String dashes = "-".repeat(car[k].count);
Copy link
Copy Markdown

@JanooGwan JanooGwan Mar 31, 2026

Choose a reason for hiding this comment

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

이 부분도 위에서 언급했던 것과 마찬가지로, 객체에 접근자를 만들어 사용하는 것을 권장합니다

String dashes = "-".repeat(car[k].getCount()):


// 빈 값 검증
if (name.isEmpty()) {
throw new IllegalArgumentException("이름은 빈 값일 수 없습니다.");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

예외처리 잘 해주셨네요! 👍👍

throw new IllegalArgumentException("이름은 빈 값일 수 없습니다.");
}
// 5자 초과 검증
if (name.length() > 5) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

이 부분도 상술한 것과 마찬가지로 상수 처리 하면 좋을 것 같습니다..!

import camp.nextstep.edu.missionutils.Randoms;

class Car {
String name;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Car 의 이름은 한 번 정해지면 바뀔 필요가 없으므로, final 로 지정해주셔도 됩니다!
그리고 Car 의 이름은 생성자에서 초기화 시키는 방향으로 하면 좋을 것 같습니다



int carCount = cars.length;
Car[] car = new Car[carCount];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

자바에서 기본적으로 제공하는 List<> 를 이용해보시는 것도 추천드립니다!
사용할 수 있는 유용한 메소드들이 많아서 정말 많이 사용되는 라이브러리입니다

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