Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Empty file removed src/main/java/.gitkeep
Empty file.
39 changes: 39 additions & 0 deletions src/main/java/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.util.Comparator;
import java.util.Random;
import javax.management.RuntimeErrorException;

public class Car{

public int pos=0;
public int carId;

Choose a reason for hiding this comment

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

carId라는 필드를 추가한 이유가 있을까요?

Copy link
Author

Choose a reason for hiding this comment

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

Name을 생성해야 한다는 규칙을 못 봤습니다.. 그래서 키값으로 Name 대신 Id를 두었습니다.

public int rank;

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.

3단계에서 있는 항목이라 생각했는데 1단계부터 있었군요..
(체크리스트 작성의 필요성을 확실히 느꼈습니다..)

private int RAND_MAX = 9;

Choose a reason for hiding this comment

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

공통적으로 사용하는 변수는 어떻게 정의하면 좋을까요?



public Car(int Id) {
this.pos = 0;
this.carId = Id;
}

public void move() {
int rand = getRandNum();
go(rand);
}

public void go(int num) {

Choose a reason for hiding this comment

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

go가 외부에서 호출되지 않을 것 같은 함수인데 그러면 private으로 바꾸는 건 어떨까요?

if (num < 3) {
pos +=1;
return;
}
if (num < 9) {
return;
}
throw new RuntimeException("예상치 못한 랜덤값 입력");
}

public int getRandNum() {
Random random = new Random();
int randNum = random.nextInt(RAND_MAX);
return randNum;
}
}
Empty file removed src/test/java/.gitkeep
Empty file.