Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
154 commits
Select commit Hold shift + click to select a range
7e31e8d
chore: add wlgns branch
kangwlgns Jun 2, 2024
64c7d42
docs: write README.md
kangwlgns Jun 2, 2024
eb6c537
feat(model): add CarModelInterface
kangwlgns Jun 2, 2024
9b426a1
feat(service): add CarServiceInterface
kangwlgns Jun 2, 2024
13e269a
feat(model): add RaceModelInterface
kangwlgns Jun 2, 2024
94487ba
feat(service): add RaceServiceInterface
kangwlgns Jun 2, 2024
2741cc5
feat(view): add RaceViewInterface
kangwlgns Jun 2, 2024
8d098e1
feat(controller): add RaceControllerInterface
kangwlgns Jun 2, 2024
5ea57ae
feat(CarModelInterface): fix a parameter of setProgress
kangwlgns Jun 2, 2024
8cf797c
feat(model): add Car
kangwlgns Jun 2, 2024
57f1d1c
feat(observer): add Observer
kangwlgns Jun 2, 2024
86e7f18
feat(observer): add Subject
kangwlgns Jun 2, 2024
141e6f7
docs: update README.md
kangwlgns Jun 2, 2024
1281fad
Merge branch 'wlgns' of https://github.com/kangwlgns/java-racingcar-p…
kangwlgns Jun 2, 2024
ac67987
feat(RaceModelInterface): remove numberOfRounds setter
kangwlgns Jun 2, 2024
91cf6c1
feat(RaceServiceInterface): add cars getter
kangwlgns Jun 2, 2024
3794feb
feat(RaceServiceInterface): remove numberOfRounds setter
kangwlgns Jun 2, 2024
c49b669
feat(model): add Race
kangwlgns Jun 2, 2024
51b745b
feat(service): add CarService
kangwlgns Jun 2, 2024
e98793a
style(CarService) add Override annotation
kangwlgns Jun 2, 2024
bd7bb61
fix(Race): fix wrong implementation
kangwlgns Jun 2, 2024
ed4a123
feat(RaceServiceInterface): add addCar
kangwlgns Jun 2, 2024
5a84c58
feat(service): add RaceService
kangwlgns Jun 2, 2024
83ff9f1
feat(RaceModelInterface): add addCar
kangwlgns Jun 2, 2024
f9311c9
feat(Race): add addCar
kangwlgns Jun 2, 2024
27d6ff8
feat(test): add tests
kangwlgns Jun 2, 2024
cc46845
feat(view): add RaceView
kangwlgns Jun 2, 2024
f80fb0e
feat(controller): add RaceController
kangwlgns Jun 2, 2024
6ca30e6
style: rewrite for the convention
kangwlgns Jun 3, 2024
604ce5e
feat(RaceControllerInterface): change a parameter of addCar and name …
kangwlgns Jun 4, 2024
60a2913
feat(RaceControllerInterface): change a parameter of addCars
kangwlgns Jun 4, 2024
add6434
feat(RaceView): add userCarsInput method
kangwlgns Jun 4, 2024
b8c4593
feat(RaceModelInterface): change a parameter of addCar and name to ad…
kangwlgns Jun 4, 2024
9850b72
feat(observer): add SubjectModel class
kangwlgns Jun 4, 2024
1286d87
change implementation from Subject to SubjectModel
kangwlgns Jun 4, 2024
19fc2de
feat(RaceModelInterface): remove addCars method
kangwlgns Jun 4, 2024
6b07ef9
feat(RaceServiceInterface): change a parameter of
kangwlgns Jun 4, 2024
f6be865
feat(RaceService): change a parameter of addCar and name to addCars
kangwlgns Jun 4, 2024
a0b5e18
feat(RaceViewInterface): add two methods which print an error message
kangwlgns Jun 4, 2024
d13ede9
feat(RaceController): add addCars method
kangwlgns Jun 4, 2024
655c09f
feat(RaceView): add two implementation methods
kangwlgns Jun 4, 2024
4d5d5c9
docs(RaceController): add comments for addCars
kangwlgns Jun 4, 2024
1abfc56
feat(Race): remove a constructor which accept one parameter
kangwlgns Jun 4, 2024
d554e07
feat(RaceModelInterface): add setNumberOfRounds method
kangwlgns Jun 5, 2024
90f7a8f
feat(Race): add setNumberOfRounds method
kangwlgns Jun 5, 2024
419933e
feat(RaceServiceInterface): add setNumberOfRounds method
kangwlgns Jun 5, 2024
0084a06
feat(RaceService): add setNumberOfRounds method
kangwlgns Jun 5, 2024
2831489
feat(RaceController): add setRound method
kangwlgns Jun 5, 2024
481834f
feat(RaceView): add userRoundsInput method
kangwlgns Jun 5, 2024
f0b5507
feat(RaceControllerInterface): change a parameter of setRound method
kangwlgns Jun 5, 2024
268f496
feat(RaceController): change a parameter's type of setRound method
kangwlgns Jun 5, 2024
618b019
feat(RaceModelInterface): change a parameter's type of setNumberOfRou…
kangwlgns Jun 5, 2024
8ad8f59
feat(RaceModelInterface): change a parameter's type of setNumberOfRou…
kangwlgns Jun 5, 2024
edb3fd2
feat(RaceServiceInterface): change a parameter's type of setNumberOfR…
kangwlgns Jun 5, 2024
685e36c
feat(RaceView): add a condition for the user input
kangwlgns Jun 5, 2024
804f548
feat(RaceService): add setNumberOfRounds method
kangwlgns Jun 5, 2024
3979b32
feat(RaceServiceInterface): change a parameter's name of setNumberOfR…
kangwlgns Jun 5, 2024
b8a9722
feat(RaceView): remove a parameter of printRoundsErrorMessage method
kangwlgns Jun 5, 2024
38df144
feat(RaceViewInterface): remove a parameter of printRoundsErrorMessag…
kangwlgns Jun 5, 2024
d0da880
feat(RaceViewInterface): divide printRoundsErrorMessage in Argument a…
kangwlgns Jun 5, 2024
abd19d6
feat(RaceView): divide printRoundsErrorMessage in Argument and Format
kangwlgns Jun 5, 2024
2998d4a
feat(RaceController): add setRound method
kangwlgns Jun 5, 2024
a891207
feat(RaceController): add init method
kangwlgns Jun 5, 2024
e813bbb
feat(RaceController): add constructor
kangwlgns Jun 5, 2024
021374f
feat(RaceView): add constructor
kangwlgns Jun 5, 2024
b515610
feat(CarService): add constructor
kangwlgns Jun 5, 2024
ae8dd7d
feat(RaceService): add constructor
kangwlgns Jun 5, 2024
dcc12b4
feat(RaceService): getNumberOfCars method
kangwlgns Jun 5, 2024
8f38164
feat(RaceService): getNumberOfRounds method
kangwlgns Jun 5, 2024
f15f130
feat(RaceService): getCars method
kangwlgns Jun 5, 2024
a5408cb
feat(RaceService): add addCars method
kangwlgns Jun 5, 2024
7f26377
feat(RaceService): remote roundValidation method
kangwlgns Jun 5, 2024
47c3121
feat(CarService): remove nameValidation method
kangwlgns Jun 5, 2024
33b24e2
feat(RaceView): add update method
kangwlgns Jun 5, 2024
1191fb8
refactor(RaceService): change a parameter's name of lambda expression
kangwlgns Jun 5, 2024
361a630
feat(CarServiceInterface): add getName method and getProgress method
kangwlgns Jun 5, 2024
5859bd5
feat(CarService): implement interface's methods
kangwlgns Jun 5, 2024
3a81b85
feat(RaceView): add printProgress method
kangwlgns Jun 5, 2024
ceed480
feat(RaceView): add println at printProgress method
kangwlgns Jun 5, 2024
a3deb10
refactor(RaceView): remove a parameter of printCarsErrorMessage method
kangwlgns Jun 5, 2024
a7a52bf
refactor(RaceViewInterface): remove a parameter of printCarsErrorMess…
kangwlgns Jun 5, 2024
25e032b
docs(RaceView): write some comments
kangwlgns Jun 5, 2024
8e9cbc1
feat(RaceServiceInterface): add getWinners method
kangwlgns Jun 5, 2024
498c8c2
feat(RaceService): add getWinners method
kangwlgns Jun 5, 2024
13e9aa2
feat(RaceService): add a condition at addCars
kangwlgns Jun 5, 2024
87ec1eb
feat(RaceService): add a comment at addCars method
kangwlgns Jun 5, 2024
0c65f49
feat(RaceService): add getWinners method
kangwlgns Jun 5, 2024
4626b03
docs(RaceService): add comment at setNumberOfRounds method
kangwlgns Jun 7, 2024
092dd15
feat(RaceService): provide list instead of string for loosely coupling
kangwlgns Jun 7, 2024
f23afd3
feat(RaceServiceInterface): provide list instead of string for loosel…
kangwlgns Jun 7, 2024
73cea13
feat(RaceView): add printResult method
kangwlgns Jun 7, 2024
e508a8c
feat(RaceViewInterface): add a parameter of printResult method
kangwlgns Jun 7, 2024
69d3517
feat(RaceView): remove a parameter of printResult method and add a re…
kangwlgns Jun 7, 2024
92a4f0e
feat(RaceViewInterface): remove a parameter of printResult
kangwlgns Jun 7, 2024
f03a6a1
feat(RaceController): add end method
kangwlgns Jun 7, 2024
1cc531e
feat(RaceView): add printCarsErrorMessage method
kangwlgns Jun 7, 2024
1039beb
feat(RaceView): add printRoundsArgumentErrorMessage method
kangwlgns Jun 7, 2024
9c991de
feat(RaceView): add printRoundsFormatErrorMessage method
kangwlgns Jun 7, 2024
ff52e3d
feat(RaceView): add printProcess method
kangwlgns Jun 7, 2024
17e8e18
feat(RaceService): modify the type of getCars method
kangwlgns Jun 7, 2024
31e154c
feat(RaceServiceInterface): modify the type of getCars method
kangwlgns Jun 7, 2024
972ed2c
feat(RaceView): modify the type of carList var
kangwlgns Jun 7, 2024
6394fe2
refactor(RaceViewInterface): remove useless imports
kangwlgns Jun 7, 2024
beecb8b
refactor(RaceModelInterface): modify the type of getCars method
kangwlgns Jun 7, 2024
dd95d92
refactor(Race): modify the type of methods and vars from ArrayList to…
kangwlgns Jun 7, 2024
fa958bb
fix(Race): fix the constructor
kangwlgns Jun 7, 2024
967ed9e
refactor(RaceService): modify the type of methods and vars from Array…
kangwlgns Jun 7, 2024
b64f8f9
refactor(SubjectModel): modify the type of method from ArrayList to List
kangwlgns Jun 7, 2024
e9ab76c
refactor(RaceModelInterface): modify the type of method from ArrayLis…
kangwlgns Jun 7, 2024
7743268
fix(Race): remove implementation of SubjectModel
kangwlgns Jun 7, 2024
d541472
feat(RaceModelInterface): add a getObserver method
kangwlgns Jun 7, 2024
4c3a270
feat(RaceService): add a addObserver method
kangwlgns Jun 7, 2024
9fd3eb6
feat(RaceService): add a removeObserver method
kangwlgns Jun 7, 2024
84cdfa1
feat(RaceService): add a notifyObserver method
kangwlgns Jun 7, 2024
e7ad07e
docs(RaceService): add comments for observer methods
kangwlgns Jun 7, 2024
9365306
fix(RaceService): remove getNumberOfRounds
kangwlgns Jun 7, 2024
9d188b7
feat(RaceServiceInterface): add startRace method
kangwlgns Jun 7, 2024
153e87f
feat(RaceService): add carsChanged method
kangwlgns Jun 7, 2024
4989b39
feat(RaceService): add startRace method
kangwlgns Jun 7, 2024
60ae98a
feat(CarService): add getName method
kangwlgns Jun 7, 2024
814f0b8
feat(CarService): add getProgress method
kangwlgns Jun 7, 2024
9dbda2f
feat(CarService): add moveOrNot method
kangwlgns Jun 7, 2024
ec61f2f
feat(CarService): add goForward method
kangwlgns Jun 7, 2024
db51def
feat(RaceController): add play method
kangwlgns Jun 7, 2024
3a61dc5
docs: add comments
kangwlgns Jun 8, 2024
5f87a41
test(RaceServiceTest): add a addCarsNumberTest test
kangwlgns Jun 8, 2024
b049ad0
test(RaceServiceTest): add a addCarsNameErrorTest test
kangwlgns Jun 8, 2024
0954824
test(RaceServiceTest): add a addCarsEmptyErrorTest test
kangwlgns Jun 8, 2024
25bf107
refactor(RaceServiceTest): rename addCarsNumberTest to addCarsTest
kangwlgns Jun 8, 2024
df4e85e
test(RaceServiceTest): add getWinnersTest
kangwlgns Jun 9, 2024
975e268
refactor(Race): add addCars and verifyNumberRounds for SRP
kangwlgns Jun 9, 2024
6dcaf5e
refactor(Race): add prepareRace and verifyNumberOfRounds for SRP
kangwlgns Jun 9, 2024
1b54137
refactor(Race): move logics of subject to Race for SRP
kangwlgns Jun 9, 2024
abb9a9b
refactor(Race): move logics of subject to Race for SRP
kangwlgns Jun 9, 2024
ad47023
refactor(Car): move logics of subject to Car for SRP
kangwlgns Jun 9, 2024
9872fb4
refactor: remove CarService class
kangwlgns Jun 9, 2024
73c4779
refactor: remove public keyword of methods of all interfaces
kangwlgns Jun 9, 2024
000c2e4
refactor: change goForward method from public to private
kangwlgns Jun 9, 2024
a35002b
docs: add comments
kangwlgns Jun 9, 2024
9d00142
feat(Race): add getter of rounds
kangwlgns Jun 9, 2024
e3acf70
feat(RaceService): add getter of rounds
kangwlgns Jun 9, 2024
bc5eb94
test(RaceServiceTest): add prepareRaceTest
kangwlgns Jun 9, 2024
0ae34c3
test(RaceServiceTest): add prepareRaceParseErrorTest
kangwlgns Jun 9, 2024
d28af62
test(RaceServiceTest): add prepareRaceRangeErrorTest
kangwlgns Jun 9, 2024
bfa42bb
test(RaceServiceTest): add getWinnersTest
kangwlgns Jun 9, 2024
b2feae0
test(RaceServiceTest): add getWinnersTest
kangwlgns Jun 9, 2024
d3850f5
feat(RaceViewInterface): add RaceViewInterface method
kangwlgns Jun 9, 2024
6f2d6fd
fix(RaceView): fix the information for losing paren
kangwlgns Jun 9, 2024
bddf34f
docs(Application): add comments at Application
kangwlgns Jun 9, 2024
b90075d
fix(RaceView): fix the printResult method because it print class inst…
kangwlgns Jun 9, 2024
b59711e
refactor(RaceView): remove unused var
kangwlgns Jun 9, 2024
9fe2c6e
docs: add comments
kangwlgns Jun 10, 2024
80a7b38
fix(RaceView): fix the print statement
kangwlgns Jun 10, 2024
842f848
docs(Race): add comments
kangwlgns Jun 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 100 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,100 @@
# java-racingcar-precourse
version 1.1
# java-racingcar-precourse
### interface Observer
* update() : void
---
### interface Subject
* addObserver(Observer) : void
* removeObserver(Observer) : void
* notifyObservers() : void
---
### interface CarModelInterface
* getName() : String
* getProgress() : int
* setProgress() : void
---
### interface RaceModelInterface
* getNumberOfCars() : int
* getNumberOfRounds() : int
* setNumberOfRounds() : void
* getCars() : List\<CarServiceInterface>
---
### interface CarServiceInterface
* move() : void
---
### interface RaceServiceInterface
* getNumberOfCars() : int
* getNumberOfRounds() : int
* setNumberOfRounds() : void
---
### interface RaceViewInterface
* userCarsInput() : void
* userRoundsInput() : void
* printProgress() : void
* printProcess() : void
* printResult() : void
---
### interface RaceControllerInterface
* init() : void
* play() : void
* end() : void
* addCar(CarServiceInterface) : void
* setRound(int) : void
---
### class CarTest
* tests
---
### class RaceServiceTest
* tests
---
### class Car - model
* name : String
* progress : int
* getName() : String
* getProgress() : int
* setProgress() : void
---
### class Race : Subject, RaceServiceInterface - model
* numberOfRounds : int
* cars : List\<CarServiceInterface>
* observers : List\<Observer>
* getNumberOfCars() : int
* getNumberOfRounds() : int
* setNumberOfRounds() : void
* getCars() : List\<CarServiceInterface>
* addObserver(Observer) : void
* removeObserver(Observer) : void
* notifyObservers() : void
---
### CarService : CarServiceInterface - service
* car : CarModelInterface
* goForward() : void
* move() : void
* nameValidation() : boolean
---
### RaceService : RaceServiceInterface - service
* race : RaceModelInterface
* addCar(CarServiceInterface) : void
* setRound(int) : void
* roundValidation() : boolean
* addObserver(Observer) : void
* removeObserver(Observer) : void
* notifyObservers() : void
---
### class RaceView : Observer, RaceViewInterface - view
* raceServiceInterface : RaceServiceInterface
* raceControllerInterface : RaceControllerInterface
* userCarsInput() : void
* userRoundsInput() : void
* printProgress() : void
* printProcess() : void
* printResult() : void
---
### RaceController : RaceControllerInterface - controller
* race : RaceServiceInterface
* view : RaceViewInterface
* init() : void
* addCar(CarServiceInterface) : void
* setRound(int) : void
* play() : void
* end() : void
1 change: 1 addition & 0 deletions src/main/java/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.
43 changes: 43 additions & 0 deletions src/main/java/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import controller.RaceController;
import controller.RaceControllerInterface;
import model.Race;
import observer.Observer;
import observer.Subject;
import service.RaceService;
import service.RaceServiceInterface;
import view.RaceView;
import view.RaceViewInterface;

public class Application {

public static void main(String[] args) {
// Race 객체 생성
Race race = new Race();

// RaceService 객체 생성
RaceService raceService = new RaceService(race, race);
// RaceServivce 인스턴스를 각 인터페이스에 맞게 변수 생성. 느슨한 결합을 위함
RaceServiceInterface raceServiceInterface = raceService;
Subject subject = raceService;

// RaceView 객체 생성
RaceView raceView = new RaceView(raceServiceInterface);
// RaceView 인스턴스를 각 인터페이스에 맞게 변수 생성. 느슨한 결합을 위함.
RaceViewInterface raceViewInterface = raceView;
Observer observer = raceView;

// subject(RaceService)에 observer(raceview) 등록.
// controller의 부담을 덜기 위함.
subject.addObserver(observer);

// RaceController 생성 및 인터페이스 변수 생성
RaceControllerInterface raceController = new RaceController(raceService, raceViewInterface);
// RaceView와 RaceController가 상호 참조하므로 seatter를 사용함.
raceViewInterface.setRaceControllerInterface(raceController);

// 컨트롤러를 사용한 서비스 시작
raceController.init();
raceController.play();
raceController.end();
}
}
70 changes: 70 additions & 0 deletions src/main/java/controller/RaceController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package controller;

import service.RaceServiceInterface;
import view.RaceViewInterface;

// 실제 사용자가 조작할 컨트롤러. 이 클래스만으로 모든 로직을 수행할 수 있어야 한다.
public class RaceController implements RaceControllerInterface {

private RaceServiceInterface race;
private RaceViewInterface view;

// 생성자
public RaceController(RaceServiceInterface race, RaceViewInterface view) {
this.race = race;
this.view = view;
}

// 시작 단계에서 호출하는 메서드
@Override
public void init() {
view.userCarsInput();
view.userRoundsInput();
}

// 중간 단계에서 호출하는 메서드
@Override
public void play() {
view.printProcess();
race.startRace();
}

// 마무리 단계에서 호출하는 메서드
@Override
public void end() {
view.printResult();
}

// view에서 입력으로 들어온 차를 생성하도록 race에 전달
@Override
public void addCars(String[] cars) {
try {
// 생성 시도
race.addCars(cars);
} catch (IllegalArgumentException e) {
// 5글자를 넘은 경우, error 메시지를 출력하고
view.printCarsErrorMessage();
// 다시 view에 입력을 요청
view.userCarsInput();
}
}

// view에서 입력으로 들어온 횟수를 저장하도록 race에 전달
@Override
public void setRound(String numberOfRound) {
// 전달 시도
try {
race.prepareRace(numberOfRound);
} catch (NumberFormatException e) {
// 숫자가 아닌 경우, error 메시지를 출력
view.printRoundsFormatErrorMessage();
// 다시 view에 입력을 요청
view.userRoundsInput();
} catch (IllegalArgumentException e) {
// 숫자가 너무 큰 경우, error 메시지를 출력
view.printRoundsArgumentErrorMessage();
// 다시 view에 입력을 요청
view.userRoundsInput();
}
}
}
20 changes: 20 additions & 0 deletions src/main/java/controller/RaceControllerInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package controller;

// 실제 사용자가 조작할 컨트롤러
public interface RaceControllerInterface {

// 사용자가 조작하는 프로그램의 첫 부분
public void init();

// 사용자가 조작하는 프로그램의 중간 부분
public void play();

// 사용자가 조작하는 프로그램의 마지막 부분
public void end();

// view로부터 입력을 받아서 service로 차들의 이름을 전송하는 메서드
public void addCars(String[] cars);

// view로부터 입력을 받아서 service로 round의 횟수를 전송하는 메서드
public void setRound(String numberOfRound);
}
52 changes: 52 additions & 0 deletions src/main/java/model/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package model;

// model과 service를 분리할 필요가 없다고 생각하여 model만 사용
public class Car implements CarModelInterface {

private final String name;
private int progress;

public Car() {
name = "";
progress = 0;
}

public Car(String name, int progress) {
this.name = name;
this.progress = progress;
}

private void setProgress(int progress) {
this.progress = progress;
}

// getter
@Override
public String getName() {
return name;
}

// getter
@Override
public int getProgress() {
return progress;
}

// 한 칸 앞으로 가는 메서드
private void goForward() {
setProgress(getProgress() + 1);
}

// 난수에 따라 한 칸 전진할지 결정하는 메서드
@Override
public void moveOrNot() {
// 랜덤 변수를 생성한 후
int randomNumber = (int) (Math.random() * 10);

// 만약 4 이상이라면
if (randomNumber > 3) {
// 앞으로 전진한다.
goForward();
}
}
}
14 changes: 14 additions & 0 deletions src/main/java/model/CarModelInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package model;

// 차 하나하나에 대한 model
public interface CarModelInterface {

// car가 갖는 이름을 반환하는 메서드
String getName();

// car의 진행도를 반환하는 메서드
int getProgress();

// 차에 전진 혹은 정지를 명령하는 메서드
void moveOrNot();
}
Loading