> Array based queue in java HELP!?

Array based queue in java HELP!?

Posted at: 2014-12-18 
Below is my code for the queue. When I input nos 1-8, it prints out 1-7 then replaces 8 with 0 why is that? And also can you tell me how to improve my code without using linkedlist.

import java.util.Arrays;

import java.util.Scanner;

public class Queue {



private int[] elements; //integer values from scanner

private int size; //number of integer values in elements

private int head = 0; //front of the queue

private int tail = 0; //rear of the queue

private int count = 0; //tracks number of integer values

public static final int DEFAULT_CAPACITY = 8; //maximum capacity of elements[]

public Queue()

{

this(DEFAULT_CAPACITY);

}



public Queue(int capacity)

{

elements = new int[capacity];

}



public void enqueue(int v)

{

elements[tail] = v;

tail = (tail + 1) % DEFAULT_CAPACITY;

count++;

}



public void dequeue(int t){

t = elements[head];

head = (head + 1) % DEFAULT_CAPACITY;

count--;

}

public boolean isEmpty(){

return head == tail;

}



public boolean isFull(){

return (tail + 1) % DEFAULT_CAPACITY == head;

}



public int getSize(){

return this.size;

}



public String toString(){

return("head--> " + Arrays.toString(elements) + " -->tail");

}