# 객체 조합하기 일단 계속 해보니깐 작성할 수 있게 되었는데 암기한것 같아서요 ㅠㅠ.. 만약 처음부터 구현한다고 가정하면 어떤 순서로 생각을 해내야 할까요? 큰틀은 알겠는데 그 안에서 2개의 클래스를 만들거나 메소드영역에서 포문을 돌리는 디테일에서 어려움을 느낍니다.. #### CODE <a class='btn btn-default' href='/codes/78971'>Link</a> ``` public class TeamTest { public static void main(String[] args) { //객체 생성 Player Kim = new Player("Kim", new int[] {9,8,10}); Player Lee = new Player("Lee", new int[] {10,9,10}); Player Park = new Player("Park", new int[] {8,10,9}); Player Xiao = new Player("Xiao", new int[] {10,9,10}); Player Yu = new Player("Yu", new int[] {8,9,10}); Player Xui = new Player("Xui", new int[] {8,9,9}); //객체 배열생성 Player[] koreaPlayer = {Kim,Lee,Park}; Player[] chinaPlayer = {Xiao,Yu,Xui}; //나라 객체 생성 Team korea = new Team("KOREA",koreaPlayer); Team china = new Team("CHINA",chinaPlayer); //출력 korea.printTeamPoints(); china.printTeamPoints(); } } class Team { //필드 String nation; Player[] players; //생성자 Team (String nation, Player[] players){ this.nation = nation; this.players = players; } //메소드 void printTeamPoints(){ int sum = 0; for (int i = 0; i < players.length; i++){ sum += players[i].totalPoints(); } System.out.printf("%s -> %d points\n", nation , sum); } } class Player { //필드 String name; int[] points; //생성자 Player (String name, int[] points){ this.name = name; this.points = points; } //메소드 int totalPoints(){ int sum = 0; for(int i = 0; i < points.length; i++){ sum += points[i]; } return sum; } } ``` #### INPUT ``` ``` #### OUPUT ``` KOREA -> 83 points CHINA -> 82 points ```
## 처음은 다 그런겁니다 모방을 통해 배우고, 그 배움을 숙달시켜 내 것으로 만드시면 됩니다 외우기보다는 흐름을 익혀보라능
감사합니다 열심히 할게용 !!