From 7ae0d85a38d473504177ac034c54d104eafb3d9e Mon Sep 17 00:00:00 2001 From: Yeonwoo JI <95765163+speciling@users.noreply.github.com> Date: Mon, 10 Jun 2024 03:25:25 +0900 Subject: [PATCH 01/18] =?UTF-8?q?docs:=20Readme.md=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 구현할 기능 목록 작성 --- README.md | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 491aece1..57c37284 100644 --- a/README.md +++ b/README.md @@ -1 +1,50 @@ -# java-racingcar-precourse \ No newline at end of file + +# java-racingcar-precourse +
+ +## 구현할 기능 목록 + +### 1. 자동차 이름 입력 메세지를 출력하고, 데이터를 입력받는 기능 +### 2. 자동차 이름 입력값을 검증하는 기능 +- 이름이 1개만 입력되었을 경우 에러 발생 +- 0글자 또는 6글자 이상의 이름이 입력되었을 경우 에러 발생 +- 중복된 이름이 입력되었을 경우 에러 발생 +### 3. 시도 횟수 입력 메세지를 출력하고, 데이터를 입력받는 기능 +### 4. 시도 횟수 입력값을 검증하는 기능 +- 입력받은 값이 1이상의 자연수가 아닐 경우 에러 발생 +### 5. 0~9 사이의 무작위 정수 생성 후, 4 이상일경우 자동차를 전진시키는 기능 +### 6. 모든 자동차의 5번 기능을 일괄적으로 실행 후 결과를 반환하는 기능 +### 7. 6번의 실행 결과를 화면에 출력하는 기능 +### 8. 우승자를 계산하는 기능 +### 9. 우승자를 출력하는 기능 +
+ +## 모듈별 클래스의 기능 정리 + +### model +1. Car + - 이름, 전진 횟수 저장 + - 0~9 사이의 랜덤 숫자 생성 후 4이상일경우 전진 횟수를 증가시키는 기능 +2. Game + - Car 객체 생성 + - 모든 Car 객체의 전진 기능 호출 후 전진 결과 반환 + - 우승자 반환 + +### view +1. InputView + - 자동차 이름 입력 메세지 출력, 입력받은 데이터 반환 + - 시도 횟수 입력 메세지 출력, 입력받은 데이터 반환 +2. MoveView + - 실행 결과 메세지 출력 + - 각 자동차의 이름과 전진 횟수 출력 +3. WinnerView + - 우승자 출력 + +### controller +1. Controller + - view에서 받은 입력을 검증하고, model에서 데이터를 받아 다시 view를 호출하며 게임을 진행하는 기능 + +### util +1. InputValidator + - 자동차 이름 입력값 검증 + - 시도 횟수 입력값 검증 \ No newline at end of file From b4497d75060988e47300c15d369aa31cba67223d Mon Sep 17 00:00:00 2001 From: Yeonwoo JI <95765163+speciling@users.noreply.github.com> Date: Mon, 10 Jun 2024 03:35:45 +0900 Subject: [PATCH 02/18] =?UTF-8?q?feat:=20=EC=9D=B4=EB=A6=84=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/view/InputView.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/view/InputView.java diff --git a/src/main/java/view/InputView.java b/src/main/java/view/InputView.java new file mode 100644 index 00000000..5bad618c --- /dev/null +++ b/src/main/java/view/InputView.java @@ -0,0 +1,12 @@ +package view; + +import java.util.Scanner; + +public class InputView { + private static final Scanner scanner = new Scanner(System.in); + + public static String inputCarNames() { + System.out.println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)"); + return scanner.nextLine(); + } +} From b2c32d756e7e4d5f120ea959385ef7e6afd7419b Mon Sep 17 00:00:00 2001 From: Yeonwoo JI <95765163+speciling@users.noreply.github.com> Date: Mon, 10 Jun 2024 04:05:38 +0900 Subject: [PATCH 03/18] =?UTF-8?q?feat:=20=EC=9D=B4=EB=A6=84=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/utils/InputValidator.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/java/utils/InputValidator.java diff --git a/src/main/java/utils/InputValidator.java b/src/main/java/utils/InputValidator.java new file mode 100644 index 00000000..ff203c22 --- /dev/null +++ b/src/main/java/utils/InputValidator.java @@ -0,0 +1,24 @@ +package utils; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class InputValidator { + public static void validateNames(List input) { + if (input.size() < 2) { + throw new IllegalArgumentException("[ERROR] 자동차 이름은 2개 이상 입력해야 합니다."); + } + + for (String name : input) { + if (name.isEmpty() || name.length() > 5) { + throw new IllegalArgumentException("[ERROR] 자동차 이름은 1~5글자여야 합니다."); + } + } + + Set names = new HashSet<>(input); + if (names.size() != input.size()) { + throw new IllegalArgumentException("[ERROR] 자동차 이름은 중복될 수 없습니다."); + } + } +} From 3d322aca68591257d319a4446f44d722a3790e99 Mon Sep 17 00:00:00 2001 From: Yeonwoo JI <95765163+speciling@users.noreply.github.com> Date: Mon, 10 Jun 2024 04:06:22 +0900 Subject: [PATCH 04/18] =?UTF-8?q?test:=20=EC=9D=B4=EB=A6=84=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EA=B8=B0=EB=8A=A5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/utils/InputValidatorTest.java | 47 +++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/test/java/utils/InputValidatorTest.java diff --git a/src/test/java/utils/InputValidatorTest.java b/src/test/java/utils/InputValidatorTest.java new file mode 100644 index 00000000..a80004c5 --- /dev/null +++ b/src/test/java/utils/InputValidatorTest.java @@ -0,0 +1,47 @@ +package utils; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.List; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class InputValidatorTest { + + @Test + @DisplayName("이름이 2개 미만 입력되었을 경우 에러 발생") + void validateNames_NamesCountsLessThanTwo_ThrowsException() { + List names = List.of("name1"); + + Assertions.assertThatThrownBy(() -> InputValidator.validateNames(names)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + @DisplayName("0글자의 이름이 입력되었을 경우 에러 발생") + void validateNames_EmptyName_ThrowsException() { + List names = List.of("name1", "name2", ""); + + Assertions.assertThatThrownBy(() -> InputValidator.validateNames(names)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + @DisplayName("6글자 이상의 이름이 입력되었을 경우 에러 발생") + void validateNames_NameLengthMoreThan6_ThrowsException() { + List names = List.of("name1", "name2", "name345"); + + Assertions.assertThatThrownBy(() -> InputValidator.validateNames(names)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + @DisplayName("중복되는 이름이 입력되었을 경우 에러 발생") + void validateNames_DuplicatedNames_ThrowsException() { + List names = List.of("name1", "name2", "name2"); + + Assertions.assertThatThrownBy(() -> InputValidator.validateNames(names)) + .isInstanceOf(IllegalArgumentException.class); + } +} \ No newline at end of file From f345dfd22080cb110f50428fdbe4e6752af8428d Mon Sep 17 00:00:00 2001 From: Yeonwoo JI <95765163+speciling@users.noreply.github.com> Date: Mon, 10 Jun 2024 04:08:16 +0900 Subject: [PATCH 05/18] =?UTF-8?q?feat:=20=EC=8B=9C=EB=8F=84=20=ED=9A=9F?= =?UTF-8?q?=EC=88=98=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/view/InputView.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/view/InputView.java b/src/main/java/view/InputView.java index 5bad618c..bc9ab1c8 100644 --- a/src/main/java/view/InputView.java +++ b/src/main/java/view/InputView.java @@ -9,4 +9,9 @@ public static String inputCarNames() { System.out.println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)"); return scanner.nextLine(); } + + public static String inputAttemptNum() { + System.out.println("시도할 회수는 몇회인가요?"); + return scanner.nextLine(); + } } From aaa2f272f358f9a2e53cd1eaba9a8044b3d58af5 Mon Sep 17 00:00:00 2001 From: Yeonwoo JI <95765163+speciling@users.noreply.github.com> Date: Mon, 10 Jun 2024 04:15:02 +0900 Subject: [PATCH 06/18] =?UTF-8?q?feat:=20=EC=8B=9C=EB=8F=84=20=ED=9A=9F?= =?UTF-8?q?=EC=88=98=20=EA=B2=80=EC=A6=9D=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/utils/InputValidator.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/utils/InputValidator.java b/src/main/java/utils/InputValidator.java index ff203c22..f88966f7 100644 --- a/src/main/java/utils/InputValidator.java +++ b/src/main/java/utils/InputValidator.java @@ -21,4 +21,15 @@ public static void validateNames(List input) { throw new IllegalArgumentException("[ERROR] 자동차 이름은 중복될 수 없습니다."); } } + + public static void validateAttemptNum(String input) { + try { + int num = Integer.parseInt(input); + if (num < 1) { + throw new IllegalArgumentException("[ERROR] 시도 횟수는 0 이하가 될 수 없습니다."); + } + } catch (NumberFormatException e) { + throw new IllegalArgumentException("[ERROR] 시도 횟수는 1 이상의 자연수로 입력해야 합니다."); + } + } } From 3ea3dcef992962d9523723f9494e2015cbeb6fd5 Mon Sep 17 00:00:00 2001 From: Yeonwoo JI <95765163+speciling@users.noreply.github.com> Date: Mon, 10 Jun 2024 04:15:21 +0900 Subject: [PATCH 07/18] =?UTF-8?q?test:=20=EC=8B=9C=EB=8F=84=20=ED=9A=9F?= =?UTF-8?q?=EC=88=98=20=EA=B2=80=EC=A6=9D=20=EA=B8=B0=EB=8A=A5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/utils/InputValidatorTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/utils/InputValidatorTest.java b/src/test/java/utils/InputValidatorTest.java index a80004c5..150f3f98 100644 --- a/src/test/java/utils/InputValidatorTest.java +++ b/src/test/java/utils/InputValidatorTest.java @@ -44,4 +44,22 @@ void validateNames_DuplicatedNames_ThrowsException() { Assertions.assertThatThrownBy(() -> InputValidator.validateNames(names)) .isInstanceOf(IllegalArgumentException.class); } + + @Test + @DisplayName("숫자가 아닌 값을 입력하면 에러 발생") + void validateAttemptNum_NotANumber_ThrowsException() { + String input = "a123"; + + Assertions.assertThatThrownBy(() -> InputValidator.validateAttemptNum(input)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + @DisplayName("입력받은 값이 0 이하의 정수일 경우 에러 발생") + void validateAttemptNum_NumberLessThanOne_ThrowsException() { + String input = "-1"; + + Assertions.assertThatThrownBy(() -> InputValidator.validateAttemptNum(input)) + .isInstanceOf(IllegalArgumentException.class); + } } \ No newline at end of file From 9acb61eee6c77e213fa5211f1c715458836fb875 Mon Sep 17 00:00:00 2001 From: Yeonwoo JI <95765163+speciling@users.noreply.github.com> Date: Mon, 10 Jun 2024 04:27:24 +0900 Subject: [PATCH 08/18] =?UTF-8?q?feat:=20=EC=9E=90=EB=8F=99=EC=B0=A8=20?= =?UTF-8?q?=EC=A0=84=EC=A7=84=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/model/Car.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/model/Car.java diff --git a/src/main/java/model/Car.java b/src/main/java/model/Car.java new file mode 100644 index 00000000..346ae3c6 --- /dev/null +++ b/src/main/java/model/Car.java @@ -0,0 +1,25 @@ +package model; + +public class Car { + private final String name; + private int position = 0; + + public Car(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public int getPosition() { + return position; + } + + public void tryMove() { + int randNum = (int)(Math.random() * 10); + if (randNum >= 4) { + position++; + } + } +} From f4509398e105ccac10612f14c7caa4d39eb645ad Mon Sep 17 00:00:00 2001 From: Yeonwoo JI <95765163+speciling@users.noreply.github.com> Date: Mon, 10 Jun 2024 04:47:58 +0900 Subject: [PATCH 09/18] =?UTF-8?q?feat:=20=EA=B2=8C=EC=9E=84=20=EC=9D=BC?= =?UTF-8?q?=EA=B4=84=20=EC=88=98=ED=96=89=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/model/Game.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/model/Game.java diff --git a/src/main/java/model/Game.java b/src/main/java/model/Game.java new file mode 100644 index 00000000..1bed3a55 --- /dev/null +++ b/src/main/java/model/Game.java @@ -0,0 +1,27 @@ +package model; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class Game { + private List cars; + + public Game(List names) { + this.cars = new ArrayList<>(); + + for (String name : names) { + cars.add(new Car(name)); + } + } + + public Map play() { + Map positions = new LinkedHashMap<>(); + for (Car car : cars) { + car.tryMove(); + positions.put(car.getName(), car.getPosition()); + } + return positions; + } +} From adc65125070255b53762cbd6553ccc98fe44c839 Mon Sep 17 00:00:00 2001 From: Yeonwoo JI <95765163+speciling@users.noreply.github.com> Date: Mon, 10 Jun 2024 04:48:04 +0900 Subject: [PATCH 10/18] =?UTF-8?q?feat:=20=EA=B2=B0=EA=B3=BC=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/view/MoveView.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/view/MoveView.java diff --git a/src/main/java/view/MoveView.java b/src/main/java/view/MoveView.java new file mode 100644 index 00000000..53755768 --- /dev/null +++ b/src/main/java/view/MoveView.java @@ -0,0 +1,16 @@ +package view; + +import java.util.Map; + +public class MoveView { + + public static void printResultMessage() { + System.out.println("\n실행 결과"); + } + + public static void printResult(Map positions) { + for (Map.Entry entry : positions.entrySet()) { + System.out.println(entry.getKey() + " : " + "-".repeat(entry.getValue())); + } + } +} From f9474fe64f686a9a87e7977537e06b5226a0a2d8 Mon Sep 17 00:00:00 2001 From: Yeonwoo JI <95765163+speciling@users.noreply.github.com> Date: Mon, 10 Jun 2024 04:50:29 +0900 Subject: [PATCH 11/18] =?UTF-8?q?refactor:=20getPosition=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/model/Game.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/model/Game.java b/src/main/java/model/Game.java index 1bed3a55..2cf8f416 100644 --- a/src/main/java/model/Game.java +++ b/src/main/java/model/Game.java @@ -16,12 +16,18 @@ public Game(List names) { } } - public Map play() { + private Map getPositions() { Map positions = new LinkedHashMap<>(); for (Car car : cars) { - car.tryMove(); positions.put(car.getName(), car.getPosition()); } return positions; } + + public Map play() { + for (Car car : cars) { + car.tryMove(); + } + return getPositions(); + } } From 36561900ed1caf0fea96dc9278f57fe4f82556f2 Mon Sep 17 00:00:00 2001 From: Yeonwoo JI <95765163+speciling@users.noreply.github.com> Date: Mon, 10 Jun 2024 05:04:56 +0900 Subject: [PATCH 12/18] =?UTF-8?q?feat:=20=EC=9A=B0=EC=8A=B9=EC=9E=90?= =?UTF-8?q?=EB=A5=BC=20=EC=B0=BE=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/model/Game.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/model/Game.java b/src/main/java/model/Game.java index 2cf8f416..b6e182af 100644 --- a/src/main/java/model/Game.java +++ b/src/main/java/model/Game.java @@ -4,6 +4,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.NoSuchElementException; public class Game { private List cars; @@ -30,4 +31,20 @@ public Map play() { } return getPositions(); } + + public List getWinners() { + Map positions = getPositions(); + List winners = new ArrayList<>(); + + int max_position = positions.values().stream() + .max(Integer::compareTo) + .orElseThrow(NoSuchElementException::new); + + for (String name : positions.keySet()) { + if (positions.get(name) == max_position) { + winners.add(name); + } + } + return winners; + } } From 762cca688fa7f8be4ae2df0857a911ccc0e614e4 Mon Sep 17 00:00:00 2001 From: Yeonwoo JI <95765163+speciling@users.noreply.github.com> Date: Mon, 10 Jun 2024 05:11:23 +0900 Subject: [PATCH 13/18] =?UTF-8?q?feat:=20=EC=9A=B0=EC=8A=B9=EC=9E=90=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/view/WinnerView.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/main/java/view/WinnerView.java diff --git a/src/main/java/view/WinnerView.java b/src/main/java/view/WinnerView.java new file mode 100644 index 00000000..768f5ed3 --- /dev/null +++ b/src/main/java/view/WinnerView.java @@ -0,0 +1,10 @@ +package view; + +import java.util.List; + +public class WinnerView { + public static void printWinners(List winners) { + System.out.println("최종 우승자 : " + String.join(", ", winners)); + } +} + From cba3cba102eca97c9445579b92bfb50f58a25682 Mon Sep 17 00:00:00 2001 From: Yeonwoo JI <95765163+speciling@users.noreply.github.com> Date: Mon, 10 Jun 2024 05:20:31 +0900 Subject: [PATCH 14/18] =?UTF-8?q?feat:=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/controller/Controller.java | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/main/java/controller/Controller.java diff --git a/src/main/java/controller/Controller.java b/src/main/java/controller/Controller.java new file mode 100644 index 00000000..7bf003b7 --- /dev/null +++ b/src/main/java/controller/Controller.java @@ -0,0 +1,40 @@ +package controller; + +import java.util.List; +import java.util.Map; +import model.Game; +import utils.InputValidator; +import view.InputView; +import view.MoveView; +import view.WinnerView; + +public class Controller { + + public static void playGame() { + List names = getNames(); + Game game = new Game(names); + + int attemptNum = getAttemptNum(); + + MoveView.printResultMessage(); + for (int i = 0; i < attemptNum; i++) { + Map positions = game.play(); + MoveView.printResult(positions); + } + + List winners = game.getWinners(); + WinnerView.printWinners(winners); + } + + private static List getNames() { + List names = List.of(InputView.inputCarNames().split(",")); + InputValidator.validateNames(names); + return names; + } + + private static int getAttemptNum() { + String attemptNumInput = InputView.inputAttemptNum(); + InputValidator.validateAttemptNum(attemptNumInput); + return Integer.parseInt(attemptNumInput); + } +} From 69afba1531edaf427ee20623db644934f5cf7934 Mon Sep 17 00:00:00 2001 From: Yeonwoo JI <95765163+speciling@users.noreply.github.com> Date: Mon, 10 Jun 2024 05:22:42 +0900 Subject: [PATCH 15/18] =?UTF-8?q?fix:=20=EA=B2=B0=EA=B3=BC=20=EC=82=AC?= =?UTF-8?q?=EC=9D=B4=EC=97=90=20=EA=B3=B5=EB=B0=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/view/MoveView.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/view/MoveView.java b/src/main/java/view/MoveView.java index 53755768..fa0a4def 100644 --- a/src/main/java/view/MoveView.java +++ b/src/main/java/view/MoveView.java @@ -12,5 +12,6 @@ public static void printResult(Map positions) { for (Map.Entry entry : positions.entrySet()) { System.out.println(entry.getKey() + " : " + "-".repeat(entry.getValue())); } + System.out.println(); } } From 7b31a4043690695420fe059db7e1081bd0047eca Mon Sep 17 00:00:00 2001 From: Yeonwoo JI <95765163+speciling@users.noreply.github.com> Date: Mon, 10 Jun 2024 05:23:23 +0900 Subject: [PATCH 16/18] =?UTF-8?q?feat:=20main=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Application.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/java/Application.java diff --git a/src/main/java/Application.java b/src/main/java/Application.java new file mode 100644 index 00000000..68c9b862 --- /dev/null +++ b/src/main/java/Application.java @@ -0,0 +1,8 @@ +import controller.Controller; + +public class Application { + + public static void main(String[] args) { + Controller.playGame(); + } +} From 94bd48d289f64459417fe0ca86ca2bf25076d5e2 Mon Sep 17 00:00:00 2001 From: speciling Date: Mon, 10 Jun 2024 12:10:36 +0900 Subject: [PATCH 17/18] =?UTF-8?q?fix:=20=EC=9E=85=EB=A0=A5=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=EC=8B=9C=20=EB=8B=A4=EC=8B=9C=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=EB=B0=9B=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/controller/Controller.java | 29 ++++++++++++++++++++---- src/main/java/view/InputView.java | 8 ++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main/java/controller/Controller.java b/src/main/java/controller/Controller.java index 7bf003b7..09390460 100644 --- a/src/main/java/controller/Controller.java +++ b/src/main/java/controller/Controller.java @@ -27,14 +27,35 @@ public static void playGame() { } private static List getNames() { - List names = List.of(InputView.inputCarNames().split(",")); - InputValidator.validateNames(names); + InputView.printCarNamesMesage(); + List names = null; + while (names == null) { + try { + names = List.of(InputView.getInput().split(",")); + InputValidator.validateNames(names); + } + catch (IllegalArgumentException e) { + System.out.println(e.toString()); + names = null; + } + } return names; } private static int getAttemptNum() { - String attemptNumInput = InputView.inputAttemptNum(); - InputValidator.validateAttemptNum(attemptNumInput); + InputView.printAttemptNumMessage(); + String attemptNumInput = null; + + while (attemptNumInput == null) { + try { + attemptNumInput = InputView.getInput(); + InputValidator.validateAttemptNum(attemptNumInput); + } + catch (IllegalArgumentException e) { + System.out.println(e.toString()); + attemptNumInput = null; + } + } return Integer.parseInt(attemptNumInput); } } diff --git a/src/main/java/view/InputView.java b/src/main/java/view/InputView.java index bc9ab1c8..227a8c27 100644 --- a/src/main/java/view/InputView.java +++ b/src/main/java/view/InputView.java @@ -5,13 +5,15 @@ public class InputView { private static final Scanner scanner = new Scanner(System.in); - public static String inputCarNames() { + public static void printCarNamesMesage() { System.out.println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)"); - return scanner.nextLine(); } - public static String inputAttemptNum() { + public static void printAttemptNumMessage() { System.out.println("시도할 회수는 몇회인가요?"); + } + + public static String getInput() { return scanner.nextLine(); } } From 5fd63744de674a68bb7fe346d817076487d1b999 Mon Sep 17 00:00:00 2001 From: speciling Date: Mon, 10 Jun 2024 12:21:02 +0900 Subject: [PATCH 18/18] =?UTF-8?q?fix:=20=EC=97=90=EB=9F=AC=20=EB=A9=94?= =?UTF-8?q?=EC=84=B8=EC=A7=80=EB=A7=8C=20=EC=B6=9C=EB=A0=A5=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/controller/Controller.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/controller/Controller.java b/src/main/java/controller/Controller.java index 09390460..a78f5e18 100644 --- a/src/main/java/controller/Controller.java +++ b/src/main/java/controller/Controller.java @@ -35,7 +35,7 @@ private static List getNames() { InputValidator.validateNames(names); } catch (IllegalArgumentException e) { - System.out.println(e.toString()); + System.out.println(e.getMessage()); names = null; } } @@ -52,7 +52,7 @@ private static int getAttemptNum() { InputValidator.validateAttemptNum(attemptNumInput); } catch (IllegalArgumentException e) { - System.out.println(e.toString()); + System.out.println(e.getMessage()); attemptNumInput = null; } }