2016-04-14 45 views
0
public class PlaneDemo 
{ 
    public static void main(String args[]) 
    { 
     ArrayQueue<Plane> q = new ArrayQueue<Plane>(); 
     Plane p1 = new Plane("Aircraft 1", 3); 
     Plane p2 = new Plane("Aircraft 2", 1); 
     Plane p3 = new Plane("Aircraft 3", 2); 

     q.addQueue(p1); 
     q.addQueue(p2); 
     q.addQueue(p3); 

     while(!q.isEmptyQueue()) 
     { 
      System.out.println("Vehicle: "); 
      System.out.println(q.front()); 
      q.deleteQueue(); 
     } 
    } 
} 
cannot find symbol 
     q.addQueue(p1); 
    ^
    symbol: method addQueue(Plane) 
    location: variable q of type ArrayQueue<Plane> 

error: cannot find symbol 
     q.addQueue(p2); 
    ^
    symbol: method addQueue(Plane) 
    location: variable q of type ArrayQueue<Plane> 

林像這樣的恐慌即將到期,我想不出我做錯了什麼。Java程序無法找到象徵

public class ArrayQueue<T> 
{ 
    private int maxQueueSize; 
    private int count; 
    private int queueFront; 
    private int queueRear; 
    private T[] list; 

    public ArrayQueue() 
    { 
     maxQueueSize = 100; 
     queueFront = 0; 
     queueRear = maxQueueSize - 1; 
     count = 0; 
     list = (T[]) new Object[maxQueueSize]; 
    } 

    public ArrayQueue(int queueSize) 
    { 
     if(queueSize <= 0) 
     { 
      System.err.println("Array size must be a positive number. Creating array at default size of 100."); 
      maxQueueSize = 100; 
     } 
     else 
      maxQueueSize = queueSize; 

     queueFront = 0; 
     queueRear = maxQueueSize - 1; 
     count = 0; 
     list = (T[]) new Object[maxQueueSize]; 
    } 

    public void initializeQueue() 
    { 
     for(int i = queueFront; i < queueRear; i = (i + 1) % maxQueueSize) 
     list[i] = null; 

     queueFront = 0; 
     queueRear = maxQueueSize - 1; 
     count = 0; 
    } 

    public boolean isEmptyQueue() 
    { 
     return(count == 0); 
    } 

    public boolean isFullQueue() 
    { 
     return(count == maxQueueSize); 
    } 

    public T peek() //throws QueueUnderflowException 
    { 
     /*if(isEmptyQueue()) 
      throw new QueueUnderflowException();*/ 

     return (T) list[queueFront]; 
    } 

    /*public T back() throws QueueOverflowException 
    { 
     if(isFullQueue()) 
      throw new QueueUnderflowException(); 
     return (T) list[queueRear]; 
    } 
*/ 
    public void enqueue(T queueElement) throws QueueOverflowException 
    { 
     if(isFullQueue()) 
      throw new QueueOverflowException(); 

     queueRear = (queueRear + 1) % maxQueueSize; 
     count++; 
     list[queueRear] = queueElement; 
    } 

    public void dequeue() throws QueueUnderflowException 
    { 
     if(isEmptyQueue()) 
      throw new QueueUnderflowException(); 

     count--; 
     list[queueFront] = null; 

     queueFront = (queueFront + 1) % maxQueueSize; 
    } 
} 
+1

什麼'ArrayQueue'的javadoc的說? – Reimeus

+0

你可以導入ArrayQueue嗎? – yogidilip

+0

ArrayQueue是你寫的一個類嗎?仔細檢查方法名稱 – Norsk

回答

0

替換此

q.addQueue(p1); 
q.addQueue(p2); 
     q.addQueue(p3); 

對於這個q.enqueue(p1); etc因爲是唯一的,方法必須將元素添加到類

public void enqueue(T queueElement) throws QueueOverflowException 
    {