I am trying to recreate the built in method Offer() myself to use to add items(Strings) to an existing Array List.
Here is my code already:
import java.util.ArrayList;
public class PriorityQueue<item> {
ArrayList<String> queue;
public PriorityQueue() {
this.queue = new ArrayList<String>();
}
public boolean offer(String item) {
//Add to queue
ensureCapacityInternal(size + 1);
elementData[size++] = e;
return true;
}
public static void main(String[] args) {
PriorityQueue myQueue = new PriorityQueue();
myQueue.offer("item1");
System.out.println(myQueue);
}
}
The issue is that when I run this I get multiple errors. The first one is:
eclipse-workspace/PriorityQueue/src/PriorityQueue.java:13:32
java: cannot find symbol
symbol: variable size
location: class PriorityQueue<item>
The second one is:
eclipse-workspace/PriorityQueue/src/PriorityQueue.java:14:9
java: cannot find symbol
symbol: variable elementData
location: class PriorityQueue<item>
I keep getting these "cannot find symbol". Why are they occuring and is there anything I can do to get this recreated offer/add method working?
Many thanks, From a coding newbie.