카운터가 제대로 작동하지 않습니다. 이 방법은 주차 차고 배열에 추가 할 차량을 수용합니다. 주차 공간은 최대 10 대의 차량을 수용 할 수 있지만, 프로그램을 실행하면 어레이의 크기가 10 세트인데도 최대 5 대의 차량 만 허용합니다.자바 카운터가 짧게 올라갑니다.
//instance variables.
private Car automobiles[]; //Array List of Cars
private int counter = 0; //counter to keep track of cars in garage.
private Car toyota; // car object
private static final int SIZE = 10;
public String arrive(Car next)
{
toyota = next;
if (counter < SIZE) // checks to make sure the garage is not full
{
automobiles[counter] = toyota; //parks new car into garage
counter++;
return "" + toyota.getlicenseNumber() + " has been parked.\n";
}
else // else statement if garage is full
{
return "Sorry, " + toyota.getlicenseNumber()
+ " cannot be parked. The Parking lot is Full!!";
}
}
다음은 instance variable
로 SIZE
static/Class variable
로하고
private int counter = 0;
counter
을 한
JAV001 has been parked.
JAV002 has been parked.
JAV003 has been parked.
JAV004 has been parked.
JAV005 has been parked.
Sorry, JAV006 cannot be parked. The Parking lot is Full!!
Sorry, JAV007 cannot be parked. The Parking lot is Full!!
Sorry, JAV008 cannot be parked. The Parking lot is Full!!
Sorry, JAV009 cannot be parked. The Parking lot is Full!!
Sorry, JAV0010 cannot be parked. The Parking lot is Full!!
스레드가 있습니까? 자동차가 제거 되었습니까? 문제를 보여주는 완전히 실행 가능한 예제를 제공 할 수 있습니까? – MadProgrammer
깨진 코드 부분이 포함되어 있지 않은 것 같습니다. 데이터를 어디에서 반복하고 있습니까? 이것은 한 번만 실행되며 출력을 생성하지 않습니다. – leigero
위의 코드가 정상으로 보였으므로 카운터 변수의 모든 참조/용도를 확인하십시오. 어쩌면 카운터가 다른 곳에서 증가하고 있습니까? – mikemil