#객체 조합하기 ## CODE <a class='btn btn-default' href='/codes/13820'>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[] koreaplayers = {kim, lee, park}; Player[] chinaplayers = {xiao, yu, xui}; Team korea = new Team("Korea", koreaplayers); Team china = new Team("China", chinaplayers); korea.totalPoints(); china.totalPoints(); } } class Player{ String name; int[] points; Player(String n, int[] p){ name = n; points = p; } int playerPoints(){ int sum = 0; for(int i = 0; i < points.length; i++){ sum += points[i]; } return sum; } } class Team{ String name; Player[] players; Team(String n, Player[] p){ name = n; players = p; } void totalPoints(){ int sum = 0; for(int i = 0; i < players.length; i++){ sum += players[i].playerPoints(); } System.out.printf("%s -> %d points\n", name, sum); } } ``` ## INPUT ``` ``` ## OUPUT ``` Korea -> 83 points China -> 82 points ``` 위 코드에서 객체배열을 생성하지 않고 선수객체생성하듯이 팀 객체를 만들때 new players[] = {x,x,x} 이런식으로 하면 안되나요?
# 가능합니다 ## 코드 예 ``` Team korea = new Team("KOREA", new Player[] { new Player("Kim", new int[] { 9, 8, 10 }), new Player("Lee", new int[] { 10, 9, 10 }), new Player("Park", new int[] { 8, 10, 9 }) }); ```