Skip to content
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

황성민 과제제출합니다. #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hll2071
Copy link

@hll2071 hll2071 commented Jul 10, 2024

No description provided.

Copy link
Member

@jyj1289 jyj1289 left a comment

Choose a reason for hiding this comment

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

너무 수고하셨습니다!
대체적으로 문제 이해를 잘못 이해하신 것 같아서 그에 대한 리뷰를 달아드렸습니다.
코드의 원리나 작동 방식등을 이해하고 코드를 작성하시면 훨씬 더 양질의 코드가 나올거에요. 너무 수고많으셨고 리뷰를 읽어보시고 수정해주시길 바라겠습니다 :)

Main.java Outdated
Comment on lines 41 to 44
for(int i=0; i<attackerlist.size(); i++) {
for(String shoot : attackerlist.get(i).ball) {
for(String goal : goalkeeperlist.get(0).keep) {
if(shoot.contains(goal)) miss[i] +=1;
Copy link
Member

@jyj1289 jyj1289 Jul 11, 2024

Choose a reason for hiding this comment

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

삼중 for문을 사용해야할 이유가 있을까요? 차라리 goalkeeper의 keep을 for문으로 두고 attacker 두 명의 슛과 비교하는게 낫지 않을까요?

Copy link
Member

Choose a reason for hiding this comment

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

contains()의 원리에 대해 생각해 보세요.

Main.java Outdated
Comment on lines 16 to 19
int[] miss = new int[2];
for(int i = 0; i < miss.length; i++) {
miss[i] = 0;
}
Copy link
Member

Choose a reason for hiding this comment

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

만약 배열을 0으로 초기화하고 싶으시다면 int[] miss = new int[]{0, 0};을 사용하여 선언하면서 초기화할 수 있습니다.

Main.java Outdated
Comment on lines 34 to 36
balls[i] = sc.nextLine();
attackerlist.get(i).ball = balls[i].split(",");
}
Copy link
Member

Choose a reason for hiding this comment

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

attackerlist.get(i).ball =sc.nextLine().split(",");
로 줄일 수 있습니다. 또한, 문제에서는 attackerlsit로 받지 않는다는 것을 명심해주세요.

Copy link
Member

Choose a reason for hiding this comment

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

또한, attackerlist는 카멜케이스를 위배합니다.

Main.java Outdated
}
String[] balls = new String[2];
String keepball;
Attacker[] attackers = new Attacker[2];
Copy link
Member

Choose a reason for hiding this comment

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

attacker1과 attacker2를 각각 ArrayList로 선언하라고 되어있습니다.

Main.java Outdated
for(int i = 0; i < attackers.length; i++) {
attackers[i] = new Attacker();
}
ArrayList<Goalkeeper> goalkeeperlist = new ArrayList<Goalkeeper>();
Copy link
Member

Choose a reason for hiding this comment

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

goalkeeper 또한 goalkeeperlist가 아닌 ArrayList로 선언하라고 되어있습니다.

Main.java Outdated
Comment on lines 6 to 12
class Attacker {
String name;
String[] ball = new String[5];
}
class Goalkeeper {
String[] keep = new String[4];
}
Copy link
Member

Choose a reason for hiding this comment

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

class가 아닌 attacker1과 attacker2, goalkeepr를 ArrayList로 선언하라고 되어있습니다.

Main.java Outdated
Comment on lines 27 to 28
goalkeeperlist.add(new Goalkeeper());
ArrayList<Attacker> attackerlist = Arrays.stream(attackers).collect(Collectors.toCollection(ArrayList::new));
Copy link
Member

Choose a reason for hiding this comment

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

이러한 코드들이 문제를 잘못 이해하여 생긴 것이죠.

Main.java Outdated
keepball = sc.nextLine();

goalkeeperlist.get(0).keep = keepball.split(",");
for(int i=0; i<attackerlist.size(); i++) {
Copy link
Member

Choose a reason for hiding this comment

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

attackerList를 사용하지 않았더라면 위와 같은 쓸모 없는 for문이 감소했겠죠.

Main.java Outdated
Comment on lines 48 to 52
if(miss[0]>miss[1]) System.out.println(attackerlist.get(1).name + "님이 승리하셨습니다.");
else if (miss[0]<miss[1]) System.out.println(attackerlist.get(0).name + "님이 승리하셨습니다.");
else System.out.println("무승부입니다.");
}
}
Copy link
Member

Choose a reason for hiding this comment

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

여기도 attackerlist가 아닌 attacker1과 attacker2라는 ArrayList를 생성한 뒤 각각처리해주세요.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants