From e9dfb5e5fceac844db42794dd0aae89202d29c5d Mon Sep 17 00:00:00 2001 From: chyjeon <125337189+chyjeon@users.noreply.github.com> Date: Sun, 10 Mar 2024 03:27:23 +0900 Subject: [PATCH] =?UTF-8?q?feat(step3):=20=EC=9E=90=EB=8F=99=EC=B0=A8=20?= =?UTF-8?q?=EA=B2=BD=EC=A3=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/racingcar/IOTest.java | 10 +++++ src/main/java/racingcar/InputView.java | 19 ++++++++ src/main/java/racingcar/OutputView.java | 15 +++++++ src/main/java/racingcar/RacingCar.java | 49 ++++++++++++++++++++ src/main/java/racingcar/RacingGame.java | 15 +++++++ src/main/java/racingcar/RacingRecord.java | 34 ++++++++++++++ src/main/java/racingcar/check.md | 10 +++++ src/test/java/racingcar/RacingTest.java | 54 +++++++++++++++++++++++ 8 files changed, 206 insertions(+) create mode 100644 src/main/java/racingcar/IOTest.java create mode 100644 src/main/java/racingcar/InputView.java create mode 100644 src/main/java/racingcar/OutputView.java create mode 100644 src/main/java/racingcar/RacingCar.java create mode 100644 src/main/java/racingcar/RacingGame.java create mode 100644 src/main/java/racingcar/RacingRecord.java create mode 100644 src/main/java/racingcar/check.md create mode 100644 src/test/java/racingcar/RacingTest.java diff --git a/src/main/java/racingcar/IOTest.java b/src/main/java/racingcar/IOTest.java new file mode 100644 index 00000000000..973923d6bc0 --- /dev/null +++ b/src/main/java/racingcar/IOTest.java @@ -0,0 +1,10 @@ +package racingcar; + +import java.io.ByteArrayInputStream; + +public abstract class IOTest { + + protected void systemIn(byte[] inputBytes) { + System.setIn(new ByteArrayInputStream(inputBytes)); + } +} \ No newline at end of file diff --git a/src/main/java/racingcar/InputView.java b/src/main/java/racingcar/InputView.java new file mode 100644 index 00000000000..ac5053cb8da --- /dev/null +++ b/src/main/java/racingcar/InputView.java @@ -0,0 +1,19 @@ +package racingcar; + +import java.util.Scanner; + +import static racingcar.RacingCar.toInts; + +public class InputView { + public static int numberOfCar(){ + System.out.println("자동차 대수는 몇 대 인가요?\n"); + return toInts((new Scanner(System.in)).nextLine()); + + } + + public static int numberOfRound(){ + System.out.println("시도할 회수는 몇 회 인가요?\n"); + return toInts((new Scanner(System.in)).nextLine()); + } + +} \ No newline at end of file diff --git a/src/main/java/racingcar/OutputView.java b/src/main/java/racingcar/OutputView.java new file mode 100644 index 00000000000..2c2a45093b6 --- /dev/null +++ b/src/main/java/racingcar/OutputView.java @@ -0,0 +1,15 @@ +package racingcar; + +public class OutputView { + public void racingResult(RacingCar racingCar){ + System.out.println(racingCar.resultOfRacing()); + } + + public void resultTitle(){ + System.out.println("실행 결과"); + } + + public void oneRoundEnd(){ + System.out.println(); + } +} diff --git a/src/main/java/racingcar/RacingCar.java b/src/main/java/racingcar/RacingCar.java new file mode 100644 index 00000000000..37120243d82 --- /dev/null +++ b/src/main/java/racingcar/RacingCar.java @@ -0,0 +1,49 @@ +package racingcar; + +import java.util.Random; + +public class RacingCar { + + private int position =0; + private String HYPHEN = "-"; + private int TEN = 10; + + private static final int THRESHOLD = 4; + + public RacingCar() { + } + + public void moveRacingCar(int randomNum){ + if (randomNum >= THRESHOLD){ + this.position ++; + } + } + + public int genRandomNum(){ + return new Random().nextInt(TEN); + } + + public String resultOfRacing(){ + String result = ""; + for (int i=0;i records = new ArrayList<>(); + + public void carRegister(int carNum){ + for (int i=0;i { + numberOfCar(); + }); + } + + @DisplayName("게임 횟수 음수나 숫자가 아니면 에러") + @ParameterizedTest + @CsvSource(value = {"-1: -1", "1#2#3: 1#2#3", "0:0"}, delimiter = ':') + void round_check(String numOfCar, String numOfRound) { + systemIn(numOfRound.getBytes()); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + numberOfRound(); + }); + + } +}