Skip to content
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d52adc5
기능 요구 사항
Kim-Dohun148 Sep 19, 2025
2d5e6e0
Car 클래스 생성
Kim-Dohun148 Sep 19, 2025
ae581f9
Car 클래스 Move함수 구현
Kim-Dohun148 Sep 19, 2025
4ca3b0f
Car 클래스 이름 입력 함수 구현
Kim-Dohun148 Sep 20, 2025
ee8ff0e
Racint 클래스 생성
Kim-Dohun148 Sep 20, 2025
cde6b87
Racint -> Racing
Kim-Dohun148 Sep 20, 2025
d30087b
Racing 클래스 시도 횟수 입력 함수 구현
Kim-Dohun148 Sep 20, 2025
e657adb
Racing 클래스 게임 진행 상황 출력 함수 구현
Kim-Dohun148 Sep 20, 2025
3744597
Racing 클래스 게임 종료 함수 구현
Kim-Dohun148 Sep 21, 2025
679a445
Racing 클래스 게임 진행 메인 함수 구현
Kim-Dohun148 Sep 21, 2025
e7b1003
기능 요구 사항 작성 완료
Kim-Dohun148 Sep 22, 2025
4fc7ffa
Racing 클래스 게임 종료 함수 수정
Kim-Dohun148 Sep 22, 2025
9f0c122
Application 코드 작성
Kim-Dohun148 Sep 22, 2025
f9d7fdf
Car 클래스 수정
Kim-Dohun148 Sep 22, 2025
30607b2
2주차 과제 리팩토링 사항 정리
Kim-Dohun148 Sep 24, 2025
cd45b64
docs : 2주차 과제 리팩토링 사항 정리
Kim-Dohun148 Sep 24, 2025
7b50757
feat : Interface 클래스 생성
Kim-Dohun148 Sep 24, 2025
4da2c20
Interface 클래스 생성 -> Interface 생성
Kim-Dohun148 Sep 24, 2025
656f8bc
feat : Interface Move 생성
Kim-Dohun148 Sep 24, 2025
f9873be
chore : 자바 네이밍 규칙에 따른 함수, 변수 이름 변경
Kim-Dohun148 Sep 26, 2025
1748a1e
chore : Car 클래스 이름 제한 수 상수화
Kim-Dohun148 Sep 26, 2025
5bd731c
chore : Racing 클래스 자바 네이밍 규칙에 따른 함수, 변수 이름 변경
Kim-Dohun148 Sep 26, 2025
08ebdf4
refactor : Racing 클래스 Car클래스와 상속 관계 수정 시작
Kim-Dohun148 Sep 26, 2025
d4af3bc
feat : Racing 클래스 getData 함수 구현
Kim-Dohun148 Sep 26, 2025
5a6e949
refactor : Racing 클래스 display 메소드 변수 재설정
Kim-Dohun148 Sep 26, 2025
0607e36
refactor : Racing 클래스 end 메소드 변수 재설정
Kim-Dohun148 Sep 26, 2025
6087109
refactor : Racing 클래스 생성자 구현 및 멤버 변수 car 생성
Kim-Dohun148 Sep 27, 2025
f6c0496
refactor : Racing 클래스 getData 메소드 삭제
Kim-Dohun148 Sep 27, 2025
8be2536
refactor : Car 클래스 멤버 변수 및 메소드 접근 제어자 재설정
Kim-Dohun148 Sep 27, 2025
8e49bce
refactor : Racing 클래스 메소드 Car 객체의 변수로 재설정
Kim-Dohun148 Sep 27, 2025
a695e83
refactor : Racing 클래스 생성자 매개변수 수정 및 메소드 변수 재설정
Kim-Dohun148 Sep 27, 2025
160fcdc
refactor : Racing 클래스 display 메소드 수정
Kim-Dohun148 Sep 27, 2025
a757a09
refactor : Application 메인 코드 작성
Kim-Dohun148 Sep 27, 2025
36208d2
style : Car 클래스 불필요 개행 삭제
Kim-Dohun148 Sep 27, 2025
42b4169
style : Racing 클래스 불필요 개행 삭제
Kim-Dohun148 Sep 27, 2025
b893357
docs : 2주차 과제 요구사항 정리
Kim-Dohun148 Sep 27, 2025
99a4904
chore : Interface 파일명 Move로 변경
Kim-Dohun148 Sep 27, 2025
bcb64f8
style Application 불필요 개행 삭제
Kim-Dohun148 Sep 27, 2025
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
33 changes: 33 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[기능 요구 사항]
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
■ 자동차 전진 또는 정지
- 전진 조건: 0~9사이 무작위 값이 4 이상인 경우

■ 자동차 이름 부여
- 각 자동차 이름은 쉼표(,)를 기준으로 구분
- 이름은 5자 이하만 가능, (잘못된 값 입력시 IllegalArgumentException을 발생시킨 후 앱 종료)
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
ㄴ Car 클래스

ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
■ 경주 게임 진행 횟수 입력 힘수
- 진행 횟수는 음수일 수 없음 (잘못된 값 입력시 IllegalArgumentException을 발생시킨 후 앱 종료)

■ 실시간 경주 게임 진행 상황 출력 함수
- 전진하는 자동차 출력시 이름도 출력

■ 경주 게임 종료 함수
- 우승자 출력
- 우승자는 한 명 이상 가능
- 우승자 여러 명일 경우 쉼표(,)를 기준으로 구분
- 진행 횟수동안 가장 많이 전진한 자동차가 우승

■ 경주 게임 진행 메인 함수
- 시도 횟수 입력받기
- 시도 횟수 동안 게임 진행
- 우승자 출력
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
ㄴ Racing 클래스



9 changes: 8 additions & 1 deletion src/main/java/racingcar/Application.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package racingcar;

import camp.nextstep.edu.missionutils.Randoms;


public class Application {
public static void main(String[] args) {
// TODO: 프로그램 구현
Car car = new Car();
Racing Game = new Racing();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

car와 Game에서 각각 소문자/대문자를 사용하신 이유가 궁금합니다!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사실 이름에 대해서는 크게 신경을 쓰지 않은 것 같습니다. 자바 네이밍 규칙 준수하겠습니다.


car.get_Car_Names();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

자바 명명법에 대해 알아보시면 좋을 것 같아요.
네이밍 규칙

Game.Start(car);
}
}
37 changes: 37 additions & 0 deletions src/main/java/racingcar/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package racingcar;

import camp.nextstep.edu.missionutils.Console;
import camp.nextstep.edu.missionutils.Randoms;

class Car {
private static final int MOVING_FORWARD = 4;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 MOVING_FORWARD와 start/end의 변수 명명을 구분하신 이유가 있으신가요?
변수와 상수의 차이에 대해 알아보시면 좋을 것 같습니다!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

자바 네이밍 규칙 준수하겠습니다.

private static final int start = 0;
private static final int end = 9;
protected String[] Car_Names;
protected int[] Move_count;

// 자동차 수 만큼 int 배열 정의
protected void get_Players_Move() { Move_count = new int[Car_Names.length]; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메서드 내용이 한 줄이어도 다른 메서드랑 같은 형태로 가져가는걸 추천드려요.


// 자동차 전진 및 정지
protected void Move() {
for (int i = 0; i < Car_Names.length; i++) {
int random = Randoms.pickNumberInRange(start, end);
if (random >= MOVING_FORWARD) { Move_count[i] += 1; }
}
}

protected void get_Car_Names() {
// 이름 입력
System.out.println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)");
String Car_String = Console.readLine();
Car_Names = Car_String.split(",");
String Car_Name;

// 이름 예외 처리
for (int i = 0; i < Car_Names.length; i++) {
Car_Name = Car_Names[i];
if (Car_Name.length() > 5) { throw new IllegalArgumentException("이름은 5자 이하만 가능합니다."); }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제한 글자수도 상수로 선언해보는 건 어떨까요?
ex) carName.length() > MAX_LENGTH

}
}
}
70 changes: 70 additions & 0 deletions src/main/java/racingcar/Racing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package racingcar;

import camp.nextstep.edu.missionutils.Console;

import java.util.ArrayList;


public class Racing extends Car {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

개념적으로 Racing(경주)와 Car(자동차)의 관계가 어떻게 되는지 한 번 더 고민해보면 좋을 것 같아요.

extends를 시도해보신 건 좋습니다!
상속은 주로 동물 > 강아지/고양이, 자동차 > 승용차/화물차 와 같은 관계에서 많이 사용이 됩니다.

private int round;

// 시도 횟수 입력 함수
public void get_round() {
// 시도 횟수 입력
System.out.println("시도할 횟수는 몇회인가요?");
String input = Console.readLine();
round = Integer.parseInt(input);

// 입력 예외 처리
if (round < 0) { throw new IllegalArgumentException("시도 횟수는 음수일 수 없습니다."); }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

예외 처리 👍

}

// 게임 진행 상황 출력 함수
public void display(Car Players) {
for (int i = 0; i < Players.Car_Names.length; i++) {
System.out.printf("%s : %s\n", Players.Car_Names[i], "-".repeat(Players.Move_count[i]));
}
System.out.println();
}

// 게임 종료 및 우승자 출력 함수
public void End(Car Players) {
ArrayList<String> Winner = new ArrayList<String>();
int max = Players.Move_count[0];

// 최대 이동횟수 찾기
for (int i = 0; i < Players.Car_Names.length; i++) {
for (int j = i + 1; j < Players.Car_Names.length; j++) {
if (max <= Players.Move_count[j]) {
max = Players.Move_count[j];
}
}
}
// 우승자 리스트 추가
for (int i = 0; i < Players.Car_Names.length; i++) {
if (Players.Move_count[i] == max) {
Winner.add(Players.Car_Names[i]);
}
}
System.out.print("최종 우승자 : ");
if (Winner.size() > 1) {
String Winners = String.join(", ", Winner);
System.out.print(Winners);
}
else { System.out.print(Winner.get(0)); }

}

// 게임 진행 메인 함수
public void Start(Car Players) {
get_round();
Players.get_Players_Move();

System.out.println("실행 결과");
for (int i = 0; i < round; i++) {
Players.Move();
display(Players);
}
End(Players);
}
}