From df15f272b936f8b336cf95fb912818812dd50e33 Mon Sep 17 00:00:00 2001 From: taein233 Date: Tue, 25 Mar 2025 21:00:24 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat=20:=20=EC=9E=90=EB=8F=99=EC=B0=A8=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EC=9E=85=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 4 +++ src/test/java/racingcar/ApplicationTest.java | 37 ++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/docs/README.md b/docs/README.md index e69de29b..df084b42 100644 --- a/docs/README.md +++ b/docs/README.md @@ -0,0 +1,4 @@ +feat : 자동차 이름 입력 +feat : 이름 5글자 이상시 오류 발생 +feat : 시도할 횟수 입력 +feat : 0~9중 랜덤한 정수 생성 \ No newline at end of file diff --git a/src/test/java/racingcar/ApplicationTest.java b/src/test/java/racingcar/ApplicationTest.java index 764ba4c6..e6acfb6c 100644 --- a/src/test/java/racingcar/ApplicationTest.java +++ b/src/test/java/racingcar/ApplicationTest.java @@ -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,42 @@ class ApplicationTest extends NsTest { ); } + public class Random{ + + } @Override public void runMain() { + Scanner sc = new Scanner(System.in); + //System.out.println("경주할 자동차 이름을 입력하세요."); + String[] name = sc.next().split(","); + for(int k = 0; k < name.length; k++){ + if(name[k].length() >= 5){ + throw new IllegalArgumentException(); + } + } + System.out.println("시도할 횟수는 몇번인가요?"); + int input_num = sc.nextInt(); + int[] name_add = new int[name.length]; + int[] ans = new int[name.length]; + for(int i = 0; i < input_num; i++) { + int[] arr_num = new int[name.length]; + for(int j= 0; j < name.length; j++) { + arr_num[j] = Randoms.pickNumberInRange(0, 9); + if (arr_num[j] >= 4) { + ans[j] += 1; + } + System.out.print(name[j] + " : "); + for (int k=0;k Date: Tue, 25 Mar 2025 21:03:25 +0900 Subject: [PATCH 2/5] =?UTF-8?q?feat=20:=20=EC=9D=B4=EB=A6=84=205=EA=B8=80?= =?UTF-8?q?=EC=9E=90=20=EC=9D=B4=EC=83=81=EC=8B=9C=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index df084b42..a624397a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ feat : 자동차 이름 입력 -feat : 이름 5글자 이상시 오류 발생 -feat : 시도할 횟수 입력 -feat : 0~9중 랜덤한 정수 생성 \ No newline at end of file +feat : 이름 글자 5글자 이상시 오류 발생 +feat : +feat : \ No newline at end of file From 41fe40e237dc9644d80c37d794f54ff54f3fa594 Mon Sep 17 00:00:00 2001 From: taein233 Date: Tue, 25 Mar 2025 21:04:11 +0900 Subject: [PATCH 3/5] =?UTF-8?q?feat=20:=20=EC=8B=9C=EB=8F=84=ED=95=A0=20?= =?UTF-8?q?=ED=9A=9F=EC=88=98=20=EC=9E=85=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index a624397a..01e5074e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ feat : 자동차 이름 입력 feat : 이름 글자 5글자 이상시 오류 발생 -feat : +feat : 시도할 횟수 입력 feat : \ No newline at end of file From 5aeed51365fece9eb3f4b5f685b2f5ffe1e83a51 Mon Sep 17 00:00:00 2001 From: taein233 Date: Tue, 25 Mar 2025 21:04:50 +0900 Subject: [PATCH 4/5] =?UTF-8?q?feat=20:=200~9=EC=A4=91=EC=97=90=EC=84=9C?= =?UTF-8?q?=20=EB=9E=9C=EB=8D=A4=ED=95=9C=20=EC=A0=95=EC=88=98=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 01e5074e..26a03fa6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ feat : 자동차 이름 입력 feat : 이름 글자 5글자 이상시 오류 발생 feat : 시도할 횟수 입력 -feat : \ No newline at end of file +feat : 0~9중에서 랜덤한 정수 생성 \ No newline at end of file From 1d0fcb325006a580dafbbb3fbf7d7eae2ce4f4d4 Mon Sep 17 00:00:00 2001 From: taein233 Date: Wed, 26 Mar 2025 02:33:20 +0900 Subject: [PATCH 5/5] =?UTF-8?q?feat=20:=200~9=EC=A4=91=EC=97=90=EC=84=9C?= =?UTF-8?q?=20=EB=9E=9C=EB=8D=A4=ED=95=9C=20=EC=A0=95=EC=88=98=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=ED=95=98=EB=8A=94=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/racingcar/Application.java | 72 +++++++++++++++++++- src/test/java/racingcar/ApplicationTest.java | 29 -------- 3 files changed, 72 insertions(+), 31 deletions(-) diff --git a/docs/README.md b/docs/README.md index 26a03fa6..15d50bb2 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ feat : 자동차 이름 입력 feat : 이름 글자 5글자 이상시 오류 발생 feat : 시도할 횟수 입력 -feat : 0~9중에서 랜덤한 정수 생성 \ No newline at end of file +feat : 0~9중에서 랜덤한 정수 생성하는 클래스 생성 \ No newline at end of file diff --git a/src/main/java/racingcar/Application.java b/src/main/java/racingcar/Application.java index a17a52e7..07bfd504 100644 --- a/src/main/java/racingcar/Application.java +++ b/src/main/java/racingcar/Application.java @@ -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 { + //우승자 출력 +} + 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])); + } + } + + 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]+","); + } + } } } diff --git a/src/test/java/racingcar/ApplicationTest.java b/src/test/java/racingcar/ApplicationTest.java index e6acfb6c..30259644 100644 --- a/src/test/java/racingcar/ApplicationTest.java +++ b/src/test/java/racingcar/ApplicationTest.java @@ -39,36 +39,7 @@ public class Random{ } @Override public void runMain() { - Scanner sc = new Scanner(System.in); - //System.out.println("경주할 자동차 이름을 입력하세요."); - String[] name = sc.next().split(","); - for(int k = 0; k < name.length; k++){ - if(name[k].length() >= 5){ - throw new IllegalArgumentException(); - } - } - System.out.println("시도할 횟수는 몇번인가요?"); - int input_num = sc.nextInt(); - int[] name_add = new int[name.length]; - int[] ans = new int[name.length]; - for(int i = 0; i < input_num; i++) { - int[] arr_num = new int[name.length]; - for(int j= 0; j < name.length; j++) { - arr_num[j] = Randoms.pickNumberInRange(0, 9); - if (arr_num[j] >= 4) { - ans[j] += 1; - } - System.out.print(name[j] + " : "); - for (int k=0;k