diff --git a/src/main/java/racingcar/Application.java b/src/main/java/racingcar/Application.java index b9ed045..f8da98d 100644 --- a/src/main/java/racingcar/Application.java +++ b/src/main/java/racingcar/Application.java @@ -1,7 +1,76 @@ package racingcar; +import java.util.ArrayList; +import java.util.List; +import camp.nextstep.edu.missionutils.Console; + + public class Application { + + private List cars; + private InputManager inputManager; + private OutputManger outputManger; + private int totalAttemptNum; + + public static void main(String[] args) { - // TODO 구현 진행 + Application app = new Application(); + app.inputManager = new InputManager(); + app.outputManger = new OutputManger(); + app.run(); + } + + public void run() { + getInfo(); + simulation(); + finishGame(); + } + + private void getInfo() { + cars = new ArrayList<>(); + + outputManger.printGetCarName(); + String[] carName = inputManager.getCar(); + + for(String name : carName) { + cars.add(new Car(name)); + } + + outputManger.printGetAttemptNum(); + this.totalAttemptNum = inputManager.getAttemptNum(); + + outputManger.printRunResultMessage(); + } + + private void simulation() { + + for(int i=0; i calWinner() { + int maxPosition = 0; + List winners = new ArrayList(); + + for (Car car : cars) { + maxPosition = Math.max(maxPosition, car.getPosition()); + } + + for (Car car : cars) { + if (car.getPosition() == maxPosition) { + winners.add(car); + } + } + + return winners; } -} + + private void finishGame() { + outputManger.printWinner(calWinner()); + } + +} \ No newline at end of file diff --git a/src/main/java/racingcar/Car.java b/src/main/java/racingcar/Car.java index ab3df94..c45cc76 100644 --- a/src/main/java/racingcar/Car.java +++ b/src/main/java/racingcar/Car.java @@ -1,12 +1,33 @@ package racingcar; +import camp.nextstep.edu.missionutils.Randoms; public class Car { private final String name; private int position = 0; - public Car(String name) { this.name = name; } - // 추가 기능 구현 + public int getPosition() { + return position; + } + + public String getName() { + return this.name; + } + + public int GenerateRandomNumber() { + int randomNumber = Randoms.pickNumberInRange(0, 9); + return randomNumber; + } + + public void CheckAdvance(int num) { + if(this.GenerateRandomNumber()>=4) { + this.position++; + } + } + + + + } diff --git a/src/main/java/racingcar/InputManager.java b/src/main/java/racingcar/InputManager.java new file mode 100644 index 0000000..1c93905 --- /dev/null +++ b/src/main/java/racingcar/InputManager.java @@ -0,0 +1,15 @@ +package racingcar; + +import camp.nextstep.edu.missionutils.Console; + +public class InputManager { + public String[] getCar() { + String input = Console.readLine(); + return input.split(","); + } + public int getAttemptNum() { + String attemptNum = Console.readLine(); + return Integer.parseInt(attemptNum); + } + +} diff --git a/src/main/java/racingcar/OutputManger.java b/src/main/java/racingcar/OutputManger.java new file mode 100644 index 0000000..b571e7f --- /dev/null +++ b/src/main/java/racingcar/OutputManger.java @@ -0,0 +1,41 @@ +package racingcar; + +import java.util.List; +import camp.nextstep.edu.missionutils.Console; +public class OutputManger { + public void printGetCarName() { + System.out.println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)"); + } + + public void printGetAttemptNum() { + System.out.println("시도할 회수는 몇회인가요?"); + } + + public void printRunResultMessage() { + System.out.println("실행 결과\n"); + } + + public void printSimulationResult(List cars) { + for (Car car : cars) { + printCarInfo(car); + } + System.out.println(); + } + + public void printCarInfo(Car car) { + System.out.print(car.getName() + " : "); + for(int i=0; i winners) { + System.out.print("최종 우승자 : "); + for(int i=0; i