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
118 changes: 118 additions & 0 deletions src/main/java/assignment.java

Choose a reason for hiding this comment

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

사용하지 않는 클래스 같은데 지워주면 좋을 것 같아요!

Copy link
Author

Choose a reason for hiding this comment

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

지웠습니다!

Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*public class assignment
{
public static void main(String[] args)
{
System.out.println("Hello, World!");
}
}*/

/*
import java.util.Scanner;

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

String name = scanner.nextLine();

System.out.println("안녕하세요, " + name + "님!");

scanner.close();
}
}*/
/*
import java.util.Scanner;

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

int num = scanner.nextInt();

if (num >0)
{
System.out.println("양수");
}
else if(num<0)
{
System.out.println("음수");
}
else
{
System.out.println("0");
}

scanner.close();
}
}*/
/*
import java.util.Scanner;

public class assignment
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int number=sc.nextInt();

switch(number)
{
case 1:
System.out.println("1");
break;
case 2:
System.out.println("2");
break;
case 3:
System.out.println("3");
break;
default:
System.out.println("No");
}
sc.close();
}
}*/
/*
public class assignment
{
public static void main(String[] args)
{
int i = 1;

while (i <= 5)
{
System.out.println(i);
i++;
}
}
}*/
/*
public class assignment
{
public static void main(String[] args)
{
for (int i = 1; i <= 5; i++)
{
System.out.println(i);
}

}
}*/

public class assignment
{
public static void main(String[] args) {

int[] numbers = {1, 2, 3, 4, 5};

for (int num : numbers)
{
System.out.println(num);
}
}
}

49 changes: 47 additions & 2 deletions src/main/java/racingcar/Application.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,52 @@
package racingcar;

public class Application {
public static void main(String[] args) {
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Application
{
public static void main(String[] args)

Choose a reason for hiding this comment

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

main 메서드 내에서 너무 많은 역할을 가지고 있는 것 같아요!
각 코드의 역할을 좀 더 알아보기 쉽게 메서드를 분리해보는게 어떨까요?

Copy link
Author

Choose a reason for hiding this comment

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

분리완료했습니다!

{
// TODO: 프로그램 구현

Scanner sc = new Scanner(System.in);

Choose a reason for hiding this comment

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

미션 요구사항에 나와있는 Console.readLine() 을 사용해주세요!

Copy link
Author

Choose a reason for hiding this comment

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

사용하여 수정하였습니다!

String[] names = sc.nextLine().split(",");

List<Car> cars = new ArrayList<>();

for (String name : names)
{
cars.add(new Car(name));
}

int count=sc.nextInt();

Choose a reason for hiding this comment

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

이상한 입력이 들어오면 어떻게 될까요?


for (int i = 0; i < count; i++) {
for (Car car : cars) {
car.movement();
System.out.println(car.getName()+ " : " + "-".repeat(car.getPosition()));
}
}

int win=0;

for(Car car:cars)
{
if(car.getPosition()>win) {
win = car.getPosition();
}
Comment on lines +36 to +38

Choose a reason for hiding this comment

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

depth가 깊어지는것 같은데 메서드로 뺄 수 있을 것 같아요~!

Copy link
Author

Choose a reason for hiding this comment

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

분리했습니다!

}
List<String> winCars = new ArrayList<>();

for(Car car: cars)
{
if(car.getPosition() == win)
{
winCars.add(car.getName());
}
}
System.out.print("winner"+String.join(", ",winCars));

Choose a reason for hiding this comment

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

ctrl + alt + L 을 통해서 라인정렬을 해 줄 수 있습니다 !

Copy link
Author

Choose a reason for hiding this comment

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

라인정렬 완료했습니다!


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

import static camp.nextstep.edu.missionutils.Randoms.pickNumberInRange;

public class Car
{
private String name;
int position = 0;

public Car(String name)
{
if (name.length() > 5)
{
throw new IllegalArgumentException("5자 이하만");

}
Comment on lines +12 to +16

Choose a reason for hiding this comment

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

이 검증 로직도 메서드로 빼줄 수 있을 것 같아요!

Copy link
Author

Choose a reason for hiding this comment

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

메서드로 뺐습니다!

this.name=name;
}

public void movement()
{
if (pickNumberInRange(0, 9) >= 4)
{
position++;
}
}

public String getName(){
return name;
}

public int getPosition(){
return position;
}
}