Link to home
Start Free TrialLog in
Avatar of perdoname_
perdoname_

asked on

Abstract method[???]

Hello there,
I have a problem with the code im compiling it and it returns an error :
"BinarySearchTree is not abstact and does not override abstract method findNums(int, int , T) in Tree"
Can anyone tell me why's that happening ???
Thanks in advance !

code:

public class BinarySearchTree<T extends Comparable<T>> implements Tree<T>{

    private Node<T> rootNode;
   
    public int min;
    public int max;
   
    public boolean isEmpty(){
        return rootNode == null;
    }
 
    public void insert(T item){
        if (rootNode == null){
            rootNode = new Node<T>(item, null, null);
        }else{
            insertNode(item, rootNode);
        }
    }
   
    //Return all the between numbers of min & max
    public  T findNums(int min, int max, Node rootNode)
    {
        if (rootNode == null)
        {
            return null;
        }
        if (rootNode.data >= min)
        {
            this.findNums(min, max, root.leftNode);
            if (root.data <= max)
            {
                System.out.println(root.data);
            }
        }
        if (root.data <= max)
        {
           this.findNums(min, max, root.rightNode);
        }
    }
 
    //Minimum node
    public T minimum(){
        if (rootNode != null){
            return findMinimumNode(rootNode).getElement();
        }else{
            return null;
        }
    }
    private Node<T> findMinimumNode(Node<T> node){
        if (node.getLeftNode() == null){
            return node;
        }else{
            return findMinimumNode(node.getLeftNode());
        }
    }
   
    private Node<T> insertNode(T item, Node<T> node){
        if (node == null){
            node = new Node<E>(item, null, null);
        }else if (item.compareTo(node.getElement()) < 0){
            node.setLeftNode(insertNode(item, node.getLeftNode()));
        }else if (item.compareTo(node.getElement()) > 0){
            node.setRightNode(insertNode(item, node.getRightNode()));
        }else{
            ;
        }
        return node;
    }
   
    private static class Node<T extends Comparable<T>>{
        private T element;
        private Node<T> leftNode;
        private Node<T> rightNode;
       
        Node(T element, Node<T>leftNode, Node<T>rightNode){
            this.element = element;
            this.leftNode = leftNode;
            this.rightNode = rightNode;
        }
       
        void setLeftNode(Node<T> leftNode){
            this.leftNode = leftNode;
        }
       
        Node<T> getLeftNode(){
            return leftNode;
        }
       
        void setRightNode(Node<T> rightNode){
            this.rightNode = rightNode;
        }
       
        Node<T> getRightNode(){
            return rightNode;
        }
       
        T getElement(){
            return element;
        }
       
        void setElement(T element){
            this.element = element;
        }
     
    }
}

ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Comparable is an interface not a class, so it has to be implemented not extended.

For abstract classes, you need to render method bodies in your subclass.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of perdoname_
perdoname_

ASKER

then what is wrong ??
:S:SS:SS
> then what is wrong ??

See the comment of TheLearnedOne http://#20836564