/**
*  This class shows an implementation of the queue abstract data type (ADT)
*  as an array.  Because it uses the Array data structure, it has a fixed
*  size which cannot be exceeded.  It will enqueue an element if the queue 
*  is not full; dequeue an element if the queue is not empty; test the queue
*  for emptyness and fullness; and it will return the value stored in the
*  element at the end of the list
*
*/

public class QueueAsArray
{
   private Customer[] myAqueue;
	private int count;  // number of elements currently in queue
	private int maxSize; // maximum number of elements queue can hold
	
	/**
	*  explicit value constructor
	*
	*/  
	public QueueAsArray (int size)
	{
	   maxSize = size;  // set maximum queue size
      myAqueue = new Customer[size];  // create an array of that size
		this.count = 0;  // no element in queue yet
	}
	
    /**
	 *  isEmpty returns true if no elements in queue, false otherwise
	 *
	 * @return  a boolean describing state of array
	 *
	 */		   
	 public boolean isEmpty()
	 { 
	    boolean returnValue;
		 
		 returnValue = false;  // assuming elements in queue
	    if (count == 0)
		   returnValue = true;
		 return returnValue;
	 }
	 
	 /** 
	 *  tells whether queue is full
	 *
	 * @return true if count = size, else false
	 *
	 */
	 public boolean isFull()
	 {
	     boolean full;  
		  
	     if (count == maxSize) 
		  {
		    full = true;
		  }	 
		  else
		  {
		     full = false;
		  }	  
	     return full;
	  }
	  
	  /**
	  *  returns first element in queue if there is one else say queue empty
	  *
	  *  @return a string containing customer name or "empty queue"
	  *
	  */
	  public String first ()
	  {
	     String returnValue;
		  if (this.isEmpty())
		     returnValue = " empty queue ";
		  else
		      returnValue = " " + myAqueue[0];
		  return returnValue;
	  } // end first 
		 	
	  /**
	  *  enQueue method adds a given value to the end of the queue if
	  *  the queue is not full, else it does nothing
	  * 
	  *  @param value to be added to the queue
	  */
	public void enqueue(Customer cName)
	{

	   if (this.count < maxSize)
		{
		   myAqueue[count] = cName;
		   this.count++;
		}
		else
		{
		   // do nothing, can't add - driver should have checked
	   }
	} // end enqueue	
	
	 /**
	  *  deQueue method removes the first item in the queue
	  *  if there is a first item.  Otherwise it does nothing
	  *
	  */
	  public void dequeue()
	  {
        if (this.count == 0) // if queue is empty
	     {
	        // do nothing
        }
	     else
	     {
            // move count-1 items forward 1 position	  
	        for (int i = 1; i < count; i++) // 
			  { 
			     myAqueue[i-1] = myAqueue[i];
			  }
			    // have one less item in queue now so decrement count
			  count--;	
		  } // end else
	} // end dequeue	
} // end QueueAsArray	  