2014-04-23 2 views
0

아직이 프로젝트에 문제가 있습니다. 내 세 번째 방법과 'Footballer PlayerIn []'부분에서 '기호를 찾을 수 없습니다'라는 메시지가 계속 표시됩니다! 당신이 나를 도울 수 있다면 크게 감사하겠습니다! 언어와개체 지향 메뉴

public static int addOne(String theArray[], int place, String theName, int noOfValues) 

{ 

int step; 

if (noOfValues == 0) 
    { 
     theArray [0] = theName; 
     noOfValues ++; 
    } 
else 
    {     
     for (step = noOfValues - 1 ; step >= place; step --) 
      { 
       theArray[step + 1] = theArray[step] ; 
      } 
     theArray[place] = theName;   
     noOfValues ++; 
    } 

return noOfValues; 
} 


public static int findPlace(String theArray[], String theName, int noOfValues) 

{ 

     int step; 
     int place; 


    step = 0 ; 
    while ((step < noOfValues) && (theName.compareTo(theArray[step]) > 0)) 
      { 
       step ++; 
      } 
     place = step ; // Holds the correct location of place 
     return place; // method must return an int 

} 

public static void listAll(Footballer PlayerIn[], int noOfValues)//displays array contents 
{ 
    int index; 

    for(index =0; index <noOfValues; index++) 
    { 
     System.out.print(PlayerIn[index]); 
    } 
} 

public static void menu() 

{ 
    System.out.println(" Menu "); 
    System.out.println(" ---------- "); 
    System.out.println(); 
    System.out.println(" 1. Add "); 
    System.out.println(" 2. Delete "); 
    System.out.println(" 3. List All "); 
    System.out.println(" 4. Exit "); 

} 


public static void options() 

{ 

char options; 


System.out.println(); 
System.out.print("Enter Option Required (1-4) "); 
options = EasyIn.getChar(); 
while (options != '4') 
{ 

     switch(options) 
      { 
       case '1': System.out.println("Add Name"); 
          EasyIn.pause(); 
          break; 
       case '2': System.out.println("Delete Name"); 
          EasyIn.pause(); 
          break; 
       case '3': System.out.println("List All"); 
          EasyIn.pause(); 
          break; 
       default: System.out.println("Invalid Option!"); 
          EasyIn.pause(); 
      } 


    System.out.println(); 
    System.out.println("Enter Option Required (1-4) "); 
    options = EasyIn.getChar(); 
} 

}

public static void main(String[] args) 

{ 
    menu(); 
    options(); 

} 

}

+0

, 그것은의 길이를 점점 목록의 수단이 불행하게도 다른 이름이 있다는 사실을 방법을 유지 그리고 당신은 파라미터 –

+0

@kolossus에서 무엇을 전달 했습니까? 제 3의 메소드를 주석 처리 할 때 그것은 않습니다. 그러나 'Footer PlayerIn []'부분에 '심볼을 찾을 수 없습니다'라고 표시되어 있습니다. – ConorDoyle21

+0

전체 스택 트레이스 표시 – kolossus

답변

0
public static void listAll(Footballer[] footballers) { 
    // displays array contents 
    for (Footballer footballer : footballers) { 
     System.out.print(footballer); 
    } 
} 

일 :

여기 내 코드입니다. 당신은 예를 들어

... 그것은 당신이 열심히 일하지 않아도 C.이 같은 자바 프로그램을 위해 노력하고

Footballer[] footballers = ...; 
int arraySize = footballers.length; 
(그들은 개체와 같은 종류의 때문에), 모든 배열은 구성원이

그리고 배열의 루프 연산자 또한 배열 전체에게 바람

for (Footballer footballer : footballers) { 
    ... 
} 

을 걷고 있습니다 "각각은"코드 "가 장소에 추가"처럼, 보이는 조작. 배열이 커지지 않기 때문에 일반적으로 그렇게하지 않으므로 마지막 요소 (또는 넘침)가 손실됩니다. Java에서는 List으로 접근합니다. ArrayList (List)을 사용하십시오. 여기서 저장소는 공간이 부족할 때 malloc 및 복사를 수행 할 수있는 크기 조절이 가능한 배열입니다. 이제 추가 기능에서 인덱스 작업을 가지고

List<Footballer> footballers = ...; 
footballers.add(5, new Footballer("Tom the Leg")); 

단지) (당신이 어디로 간지가 listAll을 사용하여 게시 할 수는 footballers.size()

관련 문제