-
Notifications
You must be signed in to change notification settings - Fork 54
[박태인_Backend] 1주차 과제 제출합니다. #51
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: main
Are you sure you want to change the base?
Changes from all commits
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,4 @@ | ||
| feat : 자동차 이름 입력 | ||
| feat : 이름 글자 5글자 이상시 오류 발생 | ||
| feat : 시도할 횟수 입력 | ||
| feat : 0~9중에서 랜덤한 정수 생성하는 클래스 생성 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,77 @@ | ||
| package racingcar; | ||
|
|
||
| import camp.nextstep.edu.missionutils.Console; | ||
| import camp.nextstep.edu.missionutils.Randoms; | ||
|
|
||
| import java.util.Scanner; | ||
| class RandomNum{ | ||
| private int num = 0; | ||
| private int car_num = 0; | ||
| public int random_num(){ | ||
| num = Randoms.pickNumberInRange(0, 9); | ||
| if(num >= 4) car_num += 1; | ||
| return car_num; | ||
| } | ||
| } | ||
| class Carprint{ | ||
| StringBuilder car_position = new StringBuilder(); | ||
|
|
||
| public String print_car(int go_car_int){ | ||
| String car_position = "-".repeat(go_car_int); | ||
| return car_position; | ||
| } | ||
| } | ||
| class Winner { | ||
| //우승자 출력 | ||
| } | ||
|
Comment on lines
+7
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 클래스들을 하나의 파일에 모두 작성하는 것은 좋지 않습니다. |
||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| // TODO: 프로그램 구현 | ||
| System.out.println("경주할 자동차 이름을 입력하세요."); | ||
| String input = Console.readLine(); | ||
| String[] name = input.split(","); | ||
| for(int k = 0; k < name.length; k++){ | ||
| if(name[k].length() >= 5){ | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
| //글자가 5이상으로 입력되고 난 뒤에 다시 입력을 받아야 하는데 이미 name 배열의 크기가 정해져 버림 | ||
| //다시 입력을 받을때 name 배열도 다시 입력되어야됨.. | ||
|
|
||
| System.out.println("시도할 횟수는 몇번인가요?"); | ||
| int input_num = Integer.parseInt(Console.readLine()); | ||
| System.out.println(input_num); | ||
| RandomNum[] cars = new RandomNum[name.length]; | ||
| Carprint[] p_cars = new Carprint[name.length]; | ||
| int[] go_number = new int[name.length]; | ||
| for(int i = 0; i < name.length; i++){ | ||
| cars[i] = new RandomNum(); | ||
| p_cars[i] = new Carprint(); | ||
| } | ||
|
|
||
|
|
||
| for(int k = 0; k < input_num; k++){ | ||
| for(int j = 0; j < name.length; j++){ | ||
| go_number[j] = cars[j].random_num(); | ||
| } | ||
|
|
||
| for(int j = 0; j < name.length; j++){ | ||
| System.out.println(name[j] + " : " + p_cars[j].print_car(go_number[j])); | ||
| } | ||
| } | ||
|
Comment on lines
+53
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 리뷰하는 3자의 입장에서 이러한 코드는 의미를 파악하기 어렵습니다. 잘 모듈화해보시고, 객체지향적인 설계를 해보시길 바랍니다. |
||
|
|
||
| int max = go_number[0]; | ||
| for(int i = 0; i < name.length; i++){ | ||
| if(go_number[i] > max){ | ||
| max = go_number[i]; | ||
| } | ||
| } | ||
|
|
||
| System.out.println("최종 우승자 : "); | ||
| for(int i = 0; i < name.length; i++){ | ||
| if(go_number[i] == max){ | ||
| System.out.println(name[i]+","); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,15 @@ | ||
| package racingcar; | ||
|
|
||
| import camp.nextstep.edu.missionutils.Randoms; | ||
| import camp.nextstep.edu.missionutils.test.NsTest; | ||
| import org.junit.jupiter.api.Test; | ||
| import java.util.Scanner; | ||
|
|
||
| import static camp.nextstep.edu.missionutils.test.Assertions.assertRandomNumberInRangeTest; | ||
| import static camp.nextstep.edu.missionutils.test.Assertions.assertSimpleTest; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
| import static org.assertj.core.api.InstanceOfAssertFactories.ARRAY; | ||
|
|
||
| class ApplicationTest extends NsTest { | ||
| private static final int MOVING_FORWARD = 4; | ||
|
|
@@ -31,8 +34,13 @@ class ApplicationTest extends NsTest { | |
| ); | ||
| } | ||
|
|
||
| public class Random{ | ||
|
|
||
| } | ||
| @Override | ||
| public void runMain() { | ||
|
|
||
| Application.main(new String[]{}); | ||
|
|
||
|
Comment on lines
+37
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이건 삭제하셔도 됩니다. |
||
| } | ||
| } | ||
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.
해당 내용을 여기에 작성하신 이유가 있나요?