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.da ta);
}
}
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.getLe ftNode());
}
}
private Node<T> insertNode(T item, Node<T> node){
if (node == null){
node = new Node<E>(item, null, null);
}else if (item.compareTo(node.getEl ement()) < 0){
node.setLeftNode(insertNod e(item, node.getLeftNode()));
}else if (item.compareTo(node.getEl ement()) > 0){
node.setRightNode(insertNo de(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;
}
}
}
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.da
}
}
if (root.data <= max)
{
this.findNums(min, max, root.rightNode);
}
}
//Minimum node
public T minimum(){
if (rootNode != null){
return findMinimumNode(rootNode).
}else{
return null;
}
}
private Node<T> findMinimumNode(Node<T> node){
if (node.getLeftNode() == null){
return node;
}else{
return findMinimumNode(node.getLe
}
}
private Node<T> insertNode(T item, Node<T> node){
if (node == null){
node = new Node<E>(item, null, null);
}else if (item.compareTo(node.getEl
node.setLeftNode(insertNod
}else if (item.compareTo(node.getEl
node.setRightNode(insertNo
}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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
then what is wrong ??
:S:SS:SS
:S:SS:SS
For abstract classes, you need to render method bodies in your subclass.