-
Notifications
You must be signed in to change notification settings - Fork 96
[자동차 경주] 이해찬 4단계 미션 제출합니다. #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: lhc0312
Are you sure you want to change the base?
Changes from 1 commit
a5fe8ce
77ecf63
4e22499
bd8257e
5f81c06
dd8a47c
ec2c76d
209d1f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| public int rank; | ||
|
||
| private int RAND_MAX = 9; | ||
|
||
|
|
||
|
|
||
| public Car(int Id) { | ||
| this.pos = 0; | ||
| this.carId = Id; | ||
| } | ||
|
|
||
| public void move() { | ||
| int rand = getRandNum(); | ||
| go(rand); | ||
| } | ||
|
|
||
| public void go(int num) { | ||
|
||
| 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; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
carId라는 필드를 추가한 이유가 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name을 생성해야 한다는 규칙을 못 봤습니다.. 그래서 키값으로 Name 대신 Id를 두었습니다.