public class CircularArrayQ implements Queue
{
	private Object [ ] rep;
	private int front;			// the index of the front member
	private int rear;			// the first available index for the next member
	private int size;
	private int capacity;

	private void reset( ) { front = -1; rear = 0; }

	public CircularArrayQ(int c) 
	{ 
		rep = new Object[c]; 
		capacity = c;
		size = 0;
		front = -1; 
		rear = 0; 
	}
	public boolean isEmpty( ) { return front == -1; }
	public boolean isFull( ) { return rear == front; }
	public void enqueue (Object member) throws FullQueueException
	{ 
		if (!isFull( )) 
		{ 
			++size;
  			rep[rear++] = member; 
			if (front == -1) { front = 0; }
			if (rear == capacity) { rear = 0; } 
		} 
		else
		{ throw new FullQueueException( ); }
	}
	public Object dequeue( ) throws EmptyQueueException
	{ 
		Object ob;

		if (!isEmpty( )) 
		{ 
			--size;
			ob = rep[front];			
			rep[front++] = null;
			if ( front == capacity )
			{ front = 0;  } 
			if (front == rear)	{ reset( ); }
		}
		else { throw new EmptyQueueException( ); }

		return ob; 
	}
	public Object front( ) throws EmptyQueueException
	{ 
		Object b = null;
		if (!isEmpty( )) 
		{ b = rep[front]; } 
		else
		{ throw new EmptyQueueException( ); }
		return b;
	}
}

