基になる構造として配列を使用して、自己作成の汎用インターフェイス「BoundedQueue」を実装しようとしています。部分的に完成したクラス「BoundedQueueArray」をコンパイルすると、次のエラーが発生します。
3 errors found:
File: C:\Users\Awet\CSC 143-Jinguji_NSCC\Week 6\csc143\data_structures\BoundedQueueArray.java [line: 11]
Error: csc143.data_structures.BoundedQueueArray is not abstract and does not override abstract method insert(java.lang.Object) in csc143.data_structures.BoundedQueue
File: C:\Users\Awet\CSC 143-Jinguji_NSCC\Week 6\csc143\data_structures\BoundedQueueArray.java [line: 20]
Error: generic array creation
File: C:\Users\Awet\CSC 143-Jinguji_NSCC\Week 6\csc143\data_structures\BoundedQueueArray.java [line: 32]
Error: name clash: insert(T) in csc143.data_structures.BoundedQueueArray and insert(T) in csc143.data_structures.BoundedQueue have the same erasure, yet neither overrides the other
クラスは次のとおりです。
package csc143.data_structures;
public class BoundedQueueArray<T> implements BoundedQueue {
// elements stored in array
private T[] elements;
// the number of elements currently in the queue
private int numElems;
public BoundedQueueArray(int capacity) {
// instantiate and bind to reference
elements = new T[capacity];
numElems = 0;
}
/**
* This method inserts the specified element, unless the
* queue is full.
*
* @param o The element to be inserted.
* @throws FullQueueException If the queue is full.
*/
public void insert(T o) throws FullQueueException {
if(numElems < elements.length) {
elements[numElems] = o;
numElems++;
} else { // queue is full, cannot add element
throw new FullQueueException("Queue is full.");
}
}
/**
* This method returns the element at the front of the
* queue, unless the queue is empty.
*
* @return The element at the front of the queue.
* @throws EmptyQueueException If the queue is empty.
*/
public T front() throws EmptyQueueException {
}
/**
* This method retrieves and removes the element at the front
* of the queue, unless the queue is empty.
*
* @return The element at the front of the queue.
* @throws EmptyQueueException If the queue is empty.
*/
public T remove() throws EmptyQueueException {
if(length() == 0) {
throw new EmptyQueueException("Queue is empty.");
}
}
/**
* This method reports whether or not the queue contains
* element(s).
*
* @return If one or more element exists or not.
*/
public boolean hasMember() {
return length() > 0;
}
/**
* This method reports whether the queue has space to add
* element(s).
*
* @return If space exists or not.
*/
public boolean hasSpace() {
return elements.length - length() > 0;
}
/**
* This method returns the capacity of the queue.
*
* @return The capacity of the queue.
*/
public int capacity() {
return elements.length;
}
/**
* This method returns the current length of the queue.
*
* @return The length of the queue.
*/
public int length() {
return numElems;
}
/**
* This method provides a string representation of the queue.
*
* @return The String representation of the queue.
*/
public String toString() {
}
}
実装するインターフェースは次のとおりです。
package csc143.data_structures;
public interface BoundedQueue<T> {
/**
* This method inserts the specified element, unless the
* queue is full.
*
* @param o The element to be inserted.
* @throws FullQueueException If the queue is full.
*/
public void insert(T o) throws FullQueueException;
/**
* This method returns the element at the front of the
* queue, unless the queue is empty.
*
* @return The element at the front of the queue.
* @throws EmptyQueueException If the queue is empty.
*/
public T front() throws EmptyQueueException;
/**
* This method retrieves and removes the element at the front
* of the queue, unless the queue is empty.
*
* @return The element at the front of the queue.
* @throws EmptyQueueException If the queue is empty.
*/
public T remove() throws EmptyQueueException;
/**
* This method reports whether or not the queue contains
* element(s).
*
* @return If one or more element exists or not.
*/
public boolean hasMember();
/**
* This method reports whether the queue has space to add
* element(s).
*
* @return If space exists or not.
*/
public boolean hasSpace();
/**
* This method returns the capacity of the queue.
*
* @return The capacity of the queue.
*/
public int capacity();
/**
* This method returns the current length of the queue.
*
* @return The length of the queue.
*/
public int length();
/**
* This method provides a string representation of the queue.
*
* @return The String representation of the queue.
*/
public String toString();
}