Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 17 additions & 3 deletions src/main/java/racingcar/Application.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
package racingcar;

import java.util.Scanner;
import java.io.IOException;
import java.util.Random;

public class Application {
public static void main(String[] args) {
// TODO: 프로그램 구현
public static <string, try1> void main(String[] args) {
Copy link

@duehee duehee Apr 4, 2025

Choose a reason for hiding this comment

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

자바에서 메인은 제공하는 psvm(public static void main(String[] args))로 서술해주셔야해요!
psvm은 무엇일까?

Scanner in = null;
Copy link

Choose a reason for hiding this comment

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

스캐너를 이렇게 작성하시면 NPE(NullPointerException)이 발생해요!
자바 Scanner 사용법
원하시는 대로 서술하시려면, 아래의 방법처럼 해주셔야 한답니다. 새로운 Scanner 객체를 생성하셔야해요.

Suggested change
Scanner in = null;
Scanner in = new Scanner(system.in);

System.out.println("자동차 이름을 적으시오 : ");
string cars = (string) in.next();
Copy link

Choose a reason for hiding this comment

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

자바에서 String은 소문자로 적으시면 안돼요! 대소문자 구분이 확실해야 한답니다

Suggested change
string cars = (string) in.next();
String cars = (string) in.next();

Copy link

Choose a reason for hiding this comment

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

  • (string)으로 캐스팅을 진행하신 이유가 있을까요?

System.out.println("자동차 이름을 적으시오 : ");
string cars2 = (string) in.next();
System.out.println("자동차 이름을 적으시오 : ");
string cars3 = (string) in.next();

System.out.println("이동 횟수를 적으시오 : ");
try1 try1 = (try1) in.next();
Copy link

Choose a reason for hiding this comment

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

try1이라는 변수를 통해서 "정수"를 받고 싶으셨던 거 같아요.
Int를 받고 싶으시다면 아래처럼 선언해야해요! 이 관련된 부분도 위의 스캐너 블로그를 참고하시면 알기 좋을 거 같아요.

Suggested change
try1 try1 = (try1) in.next();
int tryCount = in.nextInt(); //

}
}
}r
Copy link

Choose a reason for hiding this comment

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

r은 지워주셔야해요!!


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

import java.util.Random;
import java.util.Scanner;

public class carcenter {
Copy link

Choose a reason for hiding this comment

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

자바에서 클래스나 메소드 네이밍은 카멜케이스를 이용해요!
카멜케이스는 무엇일까요? 보고서에서 추가적으로 조사해보셔도 좋을 거 같아요.
자바에서의 카멜케이스는 무엇일까?

private Scanner in;
Copy link

Choose a reason for hiding this comment

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

위와 동일하게 Scanner를 선언해주셨네요. 이렇게 선언하면 어떤 문제가 생길까요?
위에 작성해드린 코드를 참고해보시고, 어떻게 수정하면 좋을지 생각해보세요!

int cars = in.nextInt();
System.out.println()
}
9 changes: 9 additions & 0 deletions src/main/java/racingcar/run.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package racingcar;

import java.io.IOException;

public class run {
public static void main(String[] args) throws IOException {
System.out.println("-" + (int)(Math.random() * 9));
Copy link

Choose a reason for hiding this comment

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

이 코드에서 의도하시고 싶으셨던 부분은 자동차의 움직임을 -로 나타내는 것이셨던 것 같은데, 이렇게 코드를 실행하면 코드가 어떻게 출력될까요?
아마.. "-3"이런 식으로 출력될 것 같아요🤔 -> 어렵다면, 다른 분들의 코드를 참고해보셔도 좋아요.

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

import java.util.Scanner;

public class scanner {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Copy link

Choose a reason for hiding this comment

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

Scanner 클래스는 이렇게 만들어주시지 않으셔도, 자바에서 제공하는 클래스에요!
이 클래스는 삭제하셔도 될 거 같아요.







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

public class winner {
Copy link

Choose a reason for hiding this comment

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

진행중이셨군요👀
추가적으로 작성하셔도 된답니다.

}