2016-10-21 2 views
-4

6 개의 개체 집합을 만들고 이름, 팀, 위치 등을 포함한 변수가 할당 된 메서드가 있습니다. 개체 배열을 검색 할 수있는 메서드가 필요합니다. 선택한 변수 (위치)로만 표시합니다. 프로젝트는 특정 위치의 플레이어 목록을 표시하도록 요구합니다. 따라서 선택된 위치가 "QB"이면 "Eli Manning" "Tom Brady" "Derek Car"와 함께 통계가 표시됩니다.위치 기반 플레이어 목록을 반환

//constructor creating 6 players 
public NFLPlayerManager(){ 
    NFLPlayer x = new NFLPlayer("Eli Manning", "New York Giants", "QB", 21, 77, 72, 170, 0, 160, "TCU"); 
    playerList.add(x); 
    NFLPlayer y = new NFLPlayer("Tom Brady", null, "QB", 0, 0, 0, 0, 0, 0, null); 
    playerList.add(y); 
    NFLPlayer z = new NFLPlayer("Josh Kline", null, null, 0, 0, 0, 0, 0, 0, null); 
    playerList.add(z); 
    NFLPlayer a = new NFLPlayer("Derek Carr", null, "QB", 0, 0, 0, 0, 0, 0, null); 
    playerList.add(a); 
    NFLPlayer b = new NFLPlayer("Rob Gronkowski", null, "TE", 0, 0, 0, 0, 0, 0, null); 
    playerList.add(b); 
    NFLPlayer c = new NFLPlayer("James White", null, null, 0, 0, 0, 0, 0, 0, null); 
    playerList.add(c); 
} 
+2

같은 함수를 호출 할 수 있습니다. 이런 질문을하는 것은 불가능합니다. – Mureinik

+3

여기에 질문이 있습니까? – Carcigenicate

+1

짐작할 필요없이 현재의 상태에서이 질문에 대답하는 것은 매우 어렵습니다. 질문을 개선하십시오. –

답변

0
public void showPlayerByPosition(String position) 
{ 
    for(int i = 0; i < playerList.size(); i++) 
    { 
     //now lets grab the NFLPlayer's position with a getter and compare it to the given string in our parameter 
     if(playerList.get(i).getposition().equals(position)) 
     { 
      //then print the NFLPlayer 
      playerList.get(i).showPlayer(); //Note i making up the name for the print function 
     } 

    } 
} 

지금 당신은 몇 가지 코드를 공유하십시오 그렇게

showPlayerbyPosition("QB")