I'm having trouble putting an object into a linked list. Here is the code:
if(runTypes[k]==EMPTY){
Empty creature = new Empty();
}
else if(runTypes[k]==FISH){
Fish creature = new Fish();
}
else if (runTypes[k]==SHARK){
Shark creature = new Shark(starveTime);
}
DLinkedList.insertEnd(creature,runLengths[k]);
However I get an error:
RunLengthEncoding.java:89: cannot find symbol
symbol : variable creature
location: class RunLengthEncoding
DLinkedList.insertEnd(creature,runLengths[k]);
^
1 error
Empty() is a super class to Fish and Shark.
Here is the code for the insertEnd method in the circularly LinkedList class:
public void insertEnd(Empty creature, int number) {
DListNode3 node = new DListNode3(creature);
head.prev.next = node;
node.next = head;
node.prev = head.prev;
head.prev=node;
node.amount = number;
size++;
}
And here is the code for the node: public class DListNode3 {
public Empty creature;
public DListNode3 prev;
public DListNode3 next;
public int amount;
DListNode3(Object creature) {
this.creature = creature;
this.amount = 1;
this.prev = null;
this.next= null;
}
DListNode3() {
this(null);
this.amount = 0;
}
}
I don't know what to do and I am new to OOP. Any advice?