-
Notifications
You must be signed in to change notification settings - Fork 55
[황명하_BackEnd] 1주차 과제 제출합니다 #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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); | ||
| } | ||
| } | ||
| } | ||
|
|
| 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. main 메서드 내에서 너무 많은 역할을 가지고 있는 것 같아요!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 분리완료했습니다! |
||
| { | ||
| // TODO: 프로그램 구현 | ||
|
|
||
| Scanner sc = new Scanner(System.in); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 미션 요구사항에 나와있는
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. depth가 깊어지는것 같은데 메서드로 뺄 수 있을 것 같아요~!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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,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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 검증 로직도 메서드로 빼줄 수 있을 것 같아요!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사용하지 않는 클래스 같은데 지워주면 좋을 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
지웠습니다!