Ok so I just posted a question and it was way too long so nobody fully read it or tried to help so I deleted that and I’m going to make this question much more specific and less of a rambling story. I would just like some help troubleshooting a class in a java program.
Here’s what the class (This is one of 6 classes needed for this assignment) should do:
“Write a fully documented class named Queue that is a subclass of Vector (or any class of your choice). Your queue class should define operations for isEmpty, enqueue, dequeue and size*, along with a constructor that defines an empty queue. Read through the Java API documentation to find out which methods act the same as enqueue and dequeue. Remember that your queue will hold items of type Object.
*the “size” method simply returns the number of elements in the queue”
Here’s what I have written so far for this class:
import java.util.Vector;
public class Queue extends Vector {
Vector<Object> line;
public Queue() {
}
public boolean isEmpty() {
if (line.isEmpty())
return true;
else
return false;
}
public void enqueue(Customer customer) {
line.addElement(customer);
}
public void dequeue() {
line.removeElementAt(0);
}
public int size() {
return elementCount;
}
}
This is in the grading rubric:
Queue class defined correctly as a subclass of Vector by using “extends” and by using the
available Vector methods (Queue class should not have an instance of a Vector inside it). Any other class may be used instead of Vector. [10 points]
I have seen the vector api so please do not simply link me to it (no offense) because I’m still having trouble understanding this. Any help on what to do is greatly appreciated.
You are requested to write a new class called
QueueisEmpty,enqueue,dequeueandsizeextend Vector(or something else that is like aVector)For example:
As documented, you should not have an instance of
Vectorin your class.As Jakub says, you will not have to implement methods that have the same name as the method in
Vector(so go ahead and remove that isEmpty method). Where you will have to do some translation is, for example: