I'm having a problem with implement interface that have a function which returns a value of a class that implement itself an interface. I have an assignment which said I need to implement those specific interfaces in this way. These are my interfaces:
public interface Something {
int getValue(); // unique
}
public interface SomethingCollection {
void add(Something something);
Something removeMaxValue();
}
This is the class that implement Something interface:
public class Node implements Something {
private int value;
private Node next;
public Node(int value) {
this.value = value;
this.next = null;
}
public Node(int value, Node next) {
this.value = value;
this.next = next;
}
public int getValue() {
return this.value;
}
public Node getNext() {
return this.next;
}
public void setNext(Node next) {
this.next = next;
}
}
And this is the class that implements SomethingCollection:
public class List implements SomethingCollection {
private Node head;
private int maxValue;
public List() {
this.head = null;
}
public List(Node p) {
Node n = new Node(p.getValue(), p.getNext());
this.head = n;
this.maxValue = this.head.getValue();
}
public void add(Node node) {
if (node.getValue() > this.maxValue) {
this.maxValue = node.getValue();
}
node.setNext(this.head);
this.head = node;
}
public Node removeMaxValue() {
Node current = this.head;
Node prev = this.head;
if (this.head == null) {
return this.head;
}
while (current != null) {
if (current.getValue() == this.maxValue) {
prev.getNext() = current.getNext();
return current;
}
prev = current;
current = current.getNext();
}
}
}
I have in List class this error: "List is not abstract and does not override abstract method add(Something) in SomethingCollection". I don't know how to fix this problem and what I'm doing wrong. How can I fix this problem?